> < ^ Date: Fri, 06 Jul 2001 18:17:35 +0200
> < ^ From: Greg Gamble <greg.gamble@math.rwth-aachen.de >
> < ^ Subject: Re: Sourcecode

GAP forum
On Fri, Jul 06, 2001 at 04:27:45PM +0100, Kurt Ewald wrote:
> Dear forum,
> is it possible to read the sourcecode of some functions of GAP4.

Dear Kurt,

Firstly, if what you want printed is indeed a function (documented with a
F) as opposed to an operation (documented with an O) and written in GAP
i.e. in the library rather than the kernel, you can use `Print' e.g. (the
"\n" just adds a new-line so you get back to a clean gap> prompt):

```gap> Print(PrimeResidues, "\n");
function ( m )
local  residues, p, i;
if m < 0  then
m := - m;
fi;
if m < 8  then
return ShallowCopy( PrimeResiduesSmall[m + 1] );
fi;
residues := [ 1 .. m - 1 ];
for p  in Set( FactorsInt( m ) )  do
for i  in [ 1 .. m / p - 1 ]  do
residues[p * i] := 1;
od;
od;
return Set( residues );
end
gap> Print(Centralizer, "\n");
function ( arg )
local  super, sub, value;
if Length( arg ) <> 2  then
return CallFuncList( oper, arg );
fi;
super := arg[1];
sub := arg[2];
if HasParent( sub ) and IsIdenticalObj( super, Parent( sub ) )  then
if Tester( attr )( sub )  then
value := attr( sub );
else
value := oper( super, sub );
Setter( attr )( sub, value );
fi;
else
value := oper( super, sub );
fi;
return value;
end
```

library and source code. Most of the library code is in the `lib'
directory (other components are in `prim' - primitive groups, `small' -
small groups, etc.) and the kernel (C code) is in the `src' directory. In
theory, it's all human-readable, though probably you will only want to
try and read the library code components: typically, functions are
declared in files with .gd extensions and then their code is in a .gi
files, but there are also .g files; mostly, if a function is declared in
<file>.gd, then its code is in <file>.gi ... in cases where this is not
true, code tends to be a little trickier to locate. On UNIX systems, this
information plus knowing about `grep' is generally enough to locate any
piece of GAP library code ... I haven't a clue how to do the equivalent
in a Windows environment.

```  Regards,