> < ^ Date: Thu, 16 Nov 1995 08:40:00 +0100 (MET)
> < ^ From: Heiko Theissen <heiko.theissen@math.rwth-aachen.de >
^ Subject: Re: Copy

Dear GAP-Forum,

Chris Wensley has reported a problem that occurs when one tries to
compare a semidirect product with a `Copy' of itself.

DIAGNOSIS:

In fact, the same problem occurs even if one tries to compare just a
semidirect product element with a copy of itself. Such elements are
represented by records which contain an entry `.domain'. This entry is
set to `GroupElements'.

When you compare two such records, GAP firsts checks whether the
`.domain' entries are equal, i.e., it compares the domains. Comparing
`GroupElements' with itself should be no problem since identical
objects are always equal in GAP. Unfortunately, since `Copy' was used,
the two instances of `GroupElements' are no longer identical (i.e. are
no longer stored in the same place in memory), and so GAP has to give
up since it cannot compare infinite domains.

gap> GroupElements = Permutations;
Error, sorry, cannot compare the infinite domains <D> and <E> in
<rec1> = <rec2> called from
main loop
gap> GroupElements = Copy( GroupElements );
Error, sorry, cannot compare the infinite domains <D> and <E> in
<rec1> = <rec2> called from
main loop

THERAPY:

Avoid `Copy'.

When you declare a local variable inside a GAP function, it is created
*anew* every time the function is called. So you do not have to use
`Copy' when you assign the value of a local variable to a non-local
variable.

In the example

test := function( x )
    local y;
    ...;  y:=...;
    x.test := y;          OR:      x.test := Copy( y );
    return y;
end;

the <y> is simply forgotten after the function has been executed and
its former value is only kept in <x.test>. So no `Copy' is required
here.

You should be aware that an assignment like `y := ...' can *never*
have side-effects on variables other than <y>. Such an assignment
makes <y> point to a new value, but it does *not* overwrite the old
value, and all other variables that may also have pointed to the old
value will still point there. Only if the left hand side of the `:='
is a record component or a list entry, the assignment *changes* the
corresponding record or list, and then *all* variables that pointed to
the same record or list will be affected.

Hope this helps, Heiko Thei{\ss}en


> < [top]