How can I find the codes related to a function in GAP? When I use "??" in front of the name of function there is no help, so I want to find the code of function among packages.
1 Answer
First, GAP is an open-source project, and both the core system and GAP packages are supplied in the GAP distribution with their source code. You may use various tools available at your system to search for a string in the source code, for example
grep -R --include=*.g* BoundPositions pkg/*
Secondly, you may print a function, for example:
gap> Print(BoundPositions);
function ( l )
return Filtered( [ 1 .. Length( l ) ], function ( i )
return IsBound( l[i] );
end );
end
gap>
In this case, the code is formatted accordingly to GAP rules, and comments in the code are not displayed.
Thirdly, you may use PageSource
to show the exact place in the file where the code is contained. In this case, you will see all comments and the author's formatting of the code. For example,
gap> PageSource(BoundPositions);
Showing source in /Users/alexk/gap4r7p5/pkg/fga/lib/util.gi (from line 6)
##
#Y 2003 - 2012
##
InstallGlobalFunction( BoundPositions,
l -> Filtered([1..Length(l)], i -> IsBound(l[i])) );
As one could see, this is an (undocumented) function from the FGA package. Clearly, the package should be loaded before using either Print(BoundPositions)
or PageSource(BoundPositions)
.
Note that the argument must be a function, so for operations, attributes, properties, filters etc. one should use ApplicableMethod
first, otherwise you may see something like this:
gap> PageSource(Size);
Cannot locate source of kernel function Size.
gap> PageSource(IsGroup);
Cannot locate source of kernel function <<and-filter>>.
Some more details are given in this GAP Forum thread and in this question.
??
is used to find the documentation, not the source. For the source, usePageSource
. See this recent thread in the GAP Forum for more details. Beware of the difference between function and operation: for the latter,ApplicableMethod
should be used first. $\endgroup$