In GAP, how can we write functions whose signatures have optional variables?

139 Views Asked by At

We know that some GAP functions present additional options in their signature. For example, consider the IsomorphicSubgroups function, if we set findall to false, it only finds one isomorphic subgroup and stops, e.g.,

gap> IsomorphicSubgroups(SmallGroup(8,3),SmallGroup(4,2):findall:=false);
[ [ f1, f2 ] -> [ f1*f3, f1 ] ]

I've used PageSource(IsomorphicSubgroups) but have failed to figure out how to do it. I would be glad if someone can explain how we can write such functions by giving a simple example.

I also wonder about whether we can define functions sharing the same name with different signatures.

1

There are 1 best solutions below

4
On BEST ANSWER

I'm, not sure what a signature would be, but what is used here is an option. The code for IsomorphicSubgroups calls

if ValueOption("findall")=false then

to go in the case of only finding one subgroup, otherwise in one to find all. If no option is given when calling the function ValueOption("findall") would return fail. You can use any string as your own option, and there is no need to formally declare it.