> < ^ Date: Thu, 12 Jan 1995 13:31:00 +0100 (WET)
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
< ^ Subject: Re: Redefining Library Functions
Lewis McCarthy wrote in his e-mail message of 1995/01/11

For my current project I'm using a modified version of one of GAP's
built-in library functions. Simply Read-ing a new definition of the
function seems to work fine, until I hit an error somewhere and enter a
break loop. Once I jump out of the break loop to the main loop, GAP seems
to revert to using the library definition of the function. Is GAP
re-reading the library files in this case, and if so, is there some
environment variable I can set to disable this behavior within a session?

Simply returning from a break loop should not result in GAP reverting to
the library definition of a function. But there are situations where GAP
reverts to the library definition. What probably happens is that GAP
reverts to the library definition *before* you enter the break loop, but
you only notice it when you return from the break loop.

To understand this, you must understand the mechanism by which GAP
reads the library.

When you start GAP, it reads the library file 'init.g'. This file
contains lines of the form

AUTO( ReadLib( "list" ),
List, Apply, Concatenation, Flat, Reversed, Sublist, Filtered, Number,
Collected, Equivalenceclasses, ForAll, ForAny, First, PositionProperty,
Cartesian2, Cartesian, Sort, SortParallel, Sortex, Permuted,
PositionSorted, Product, Sum, Iterated, Maximum, Minimum, R_N, R_X,
RandomList, RandomSeed );

This tells GAP that it should read the library file 'list.g', should it
ever need one of the functions 'List', 'Apply', etc. Basically GAP
stores in the variable 'List' the *statement* 'ReadLib("list")',
and marks the variable as 'T_VARAUTO', which means that 'List' does not
point to a value but to a statement.

Now when GAP evaluates 'List', it sees that 'List' is 'T_VARAUTO' and
evaluates the statement that 'List' points to. That is GAP reads the
library file 'list.g'. This then defines the function 'List' with the
statement

List := function ( list, func ) ...library code... end;

After this assignment 'List' has no longer type 'T_VARAUTO' but type
'T_VAR', because it no longer points to a statement, but to a value.

But at the same time GAP also reads all the other function definitions
in the file 'list.g'. This overwrites any previous definition those
variables might have had.

So assume that GAP has not yet read 'list.g'. Now redefine 'Apply'
with the following statement

Apply := function ( list, func ) ...your code... end;

Everything works fine until you need another function from 'list.g', say
'List'. Then GAP reads 'list.g' to get the definition of 'List'. But at
the same time it overwrites your new definition of 'Apply' with the
library function.

The solution is to make certain that after your redefinition of 'Apply',
GAP will not read the library file 'list.g'. The easiest way to do this
is to force GAP to read the library file 'list.g' *before* you redefine
'Apply'. This is achieved by the following code

Apply; # autoread the library file where 'Apply' is defined
Apply := function ( list, func ) ...your code... end;

This does not work for some library file <sub>, because they are not
automatically read by the mechanism described above, but read explicetely
from other library file <sup>. In this case you must read the file <sup>
(with 'ReadLib(<sup>);') before you redefine a function defined in <sub>.

<sup> <sup>
aggroup.g agprops.g agsubgrp.g aghomomo.g agcoset.g agnorm.g
aghall.g aginters.g agcomple.g agclass.g agctbl.g
onecohom.g saggroup.g sagsbgrp.g
fpgrp.g fptietze.g fpsgpres.g
group.g grphomom.g operatio.g grpcoset.g grpprods.g grpctbl.g
grplatt.g monomial.g
matrix.g matgrp.g matring.g
permutat.g permgrp.g permstbc.g permoper.g permbckt.g permnorm.g
permcose.g permhomo.g permcset.g permag.g permctbl.g
ratclass.g permprod.g
sq.g sqstuff.g

If you have such a problem, it is always a good idea to start your
session with the statements (or put them into your '.gaprc' file)

InfoRead1 := Print;
InfoRead2 := Print;

Then every time it reads a file, GAP will tell you about it.

Hope this helps,

Martin.

-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,   +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, 52056 Aachen, Germany

> < [top]