<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %W  libform.tex              GAP documentation           Alexander Hulpke -->
<!-- %% -->
<!-- %% -->

<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Chapter Label="Library Files">
<Heading>Library Files</Heading>

This chapter describes some of the conventions used in the &GAP;
library files.
These conventions are intended as a help on how to read library files and
how to find information in them.
So everybody is recommended to follow these conventions,
although they do not prescribe a compulsory programming style
&ndash;&GAP; itself will not bother with the formatting of files.
<P/>
Filenames have traditionally &GAP; adhered to the 8+3 convention (to make it
possible to use the same filenames even on a MS-DOS file system) and been in
lower case (systems that do not recognize lower case in file names will
convert them automatically to upper case). It is no longer so important to
adhere to these conventions, but at the very least filenames should adhere
to a 16+5 convention, and be distinct even after identifying upper and lower
case. Directory names of packages, however, <E>must</E> be in lower case
(the <Ref Func="LoadPackage"/> command assumes this).


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="File Types">
<Heading>File Types</Heading>

The &GAP; library consists of the following types of files, distinguished
by their suffixes:
<P/>
<List>
<Mark><C>.g</C> </Mark>
<Item>
    Files which contain parts of the <Q>inner workings</Q> of &GAP;.
    These files usually do not contain mathematical functionality,
    except for providing links to kernel functions.
</Item>
<Mark><C>.gd</C> </Mark>
<Item>
    Declaration files.
    These files contain declarations of all categories, attributes,
    operations, and global functions.
    These files also contain the operation definitions in comments.
</Item>
<Mark><C>.gi</C> </Mark>
<Item>
    Implementation files.
    These files contain all installations of methods and global functions.
    Usually declarations of representations are also considered to be
    part of the implementation and are therefore found in the <C>.gi</C> files.
</Item>
</List>
<P/>
As a rule of thumb, all <C>.gd</C> files are read in before the <C>.gi</C>
files are read.
Therefore a <C>.gi</C> file usually may use any operation or global function
(it has been declared before),
and no care has to be taken towards the order in which the <C>.gi</C> files
are read.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Finding Implementations in the Library">
<Heading>Finding Implementations in the Library</Heading>

For a concretely given function, you can use
<Ref Func="FilenameFunc"/> and <Ref Func="StartlineFunc"/> for finding the
file where this function is defined, and the line in this file where the
definition of this function starts.
This does not work for arbitrary functions,
see Section <Ref Func="FilenameFunc"/> for the restrictions.
<P/>
If you are interested in getting the function which implements a method
for specific arguments, you can use <Ref Sect="ApplicableMethod"/>.
If <Ref Func="FilenameFunc"/> does not work for this method then
setting the print level of <Ref Sect="ApplicableMethod"/> higher will give
you the installation string for this method, which can be used for searching
in library files.
<P/>
To find the occurrence of functions, methods, function names,
and installation strings in the library,
one can use the <C>grep</C> tool under UNIX.
To find a function, search for the function name in the <C>.gd</C> files;
as global variables are usually declared only once,
only few files will show up.
The function installation is likely to occur in the corresponding
<C>.gi</C> file.
<P/>
To find a method from the known operation name and the installation string,
search for the string <Q><C>Method(</C></Q>
(this catches both <Ref Func="InstallMethod"/> and
<Ref Func="InstallOtherMethod"/>)
and the installation string or the operation name.
<P/>
The following tools from the &GAP; package <Package>Browse</Package>
can be used for accessing the code of functions.
<P/>
<List>
<Item>
    <Ref Func="BrowseGapMethods" BookName="browse"/> shows an overview of
    &GAP;'s operations and methods, and allows one to navigate through the
    files that contain the implementations of the methods, using a pager.
</Item>
<Item>
    <Ref Func="BrowseProfile" BookName="browse"/> shows profiling results
    (similar to <Ref Func="DisplayProfile"/>) and allows one to navigate
    through the files that contain the implementations of the functions
    that were actually used, using a pager.
</Item>
</List>

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Undocumented Variables">
<Heading>Undocumented Variables</Heading>

For several global variables in &GAP;,
no information is available via the help system
(see Section&nbsp;<Ref Sect="Help" BookName="tut"/>,
for a quick overview of the help system,
or Chapter&nbsp;<Ref Chap="The Help System"/>,
for details).
There are various reasons for <Q>hiding</Q> a variable from the user;
namely, the variable may be regarded as of minor importance
(for example, it may be a function called by documented &GAP;
functions that first compute many input parameters for the undocumented
function),
or it belongs to a part of &GAP; that is still experimental in the sense
that the meaning of the variable has not yet been fixed or even that it is
not clear whether the variable will vanish in a more developed version.
<P/>
As a consequence, it is dangerous to use undocumented variables because
they are not guaranteed to exist or to behave the same in future versions
of &GAP;.
<P/>
Conversely, for <E>documented</E> variables, the definitions in the &GAP;
manual can be relied on for future &GAP; versions (unless they turn out
to be erroneous);
if the &GAP; developers find that some piece of minor, but documented
functionality is an insurmountable obstacle to important developments,
they may make the smallest possible incompatible change to the functionality
at the time of a major release.
However, in any such case it will be announced clearly in the &GAP; Forum
what has been changed and why.
<P/>
So on the one hand, the developers of &GAP; want to keep the freedom
of changing undocumented &GAP; code.
On the other hand, users may be interested in using undocumented
variables.
<P/>
In this case, whenever you write &GAP; code involving undocumented
variables,
and want to make sure that this code will work in future versions of &GAP;,
you may ask at <Email>support@gap-system.org</Email> for documentation
about the variables in question.
The &GAP; developers then decide whether these variables shall be
documented or not, and if yes, what the definitions shall be.
<P/>
In the former case, the new documentation is added to the &GAP; manual,
this means that from then on, this definition is protected against
changes.
<P/>
In the latter case (which may occur for example if the variables
in question are still experimental), you may add the current
values of these variables to your private code if you want to
be sure that nothing will be broken later due to changes in &GAP;.

</Section>
</Chapter>

