> < ^ Date: Wed, 20 Nov 1996 17:33:00 +0100 (MET)
> < ^ From: Thomas Breuer <Thomas.Breuer@Math.RWTH-Aachen.DE >
< ^ Subject: Re: Segmentation fault

Dear GAP-Forum,

Andreas Prinz wrote

I ran across a segmentation error with the following

gap> el:=List([1..4],x->rec(num:=x));;
gap> bl:=List([1..2],x->rec(num:=x,els:=Filtered(el,e->(e.num+x) mod 2=0)));;
gap> for b in bl do for e in b.els do e.block:=b; od; od;
gap> Set(bl);
Segmentation fault (core dumped)

I guess, it is due to the recursive nature of the structs, but
I need it to be such. Probably I can do with defining a "<"
relation for the records, but there seems to be a bug in gap

Indeed the problem occurs because the objects contain themselves as
proper substructures.
Here is how 'bl[1]' looks like before the call of 'Set'.

gap> bl[1];
  num := 1,
  els := [ rec(
          num := 1,
          block := ~ ), rec(
          num := 3,
          block := ~ ) ] )

As the GAP manual says in the section "Comparison of Records",
the comparison of records is implemented by comparing the components.
This runs into an infinite recursion in this case.
So I would not regard the behaviour as a bug.

(A simpler example is the comparison of two lists that contain themselves.

gap> l:= [];; l[1]:= l;; l;
[ ~ ]
gap> l = Copy( l );
<segmentation fault>

This runs into an infinite recursion for the same reason.)

If one knows about the internal structure of objects as in the list 'bl',
implementing a special method for '<' that looks at the non-recursive
components first will solve the problem; the details are described in the
manual section cited above.

Kind regards

> < [top]