[GAP Forum] simple programming problem

Marc Roeder marc_roeder at web.de
Tue Aug 22 08:46:31 BST 2006


Hello,

> For some reason, the generated list will have always the SAME matrix as its
> entries, whereas while still in the loop, the entries are -obviously- equal to
> the matrices x.

Your problem seems to be pointer-related.

The program manipulates the variable x. But x is just a pointer.
Add(listx,x) adds the pointer x to the list listx.
So listx contains the same pointer over and over again.

The manual has some information on this topic in section "12. Objects
and Elements".
Here is an example:

gap> a:=[1,2];
[ 1, 2 ]
gap> list:=[a];
[ [ 1, 2 ] ]
gap> a[4]:=9;;
gap> list;
[ [ 1, 2,, 9 ] ]
gap> Add(list,a);
gap> list;
[ [ 1, 2,, 9 ], [ 1, 2,, 9 ] ]
gap> a[3]:=10;;list;
[ [ 1, 2, 10, 9 ], [ 1, 2, 10, 9 ] ]

Hope this helps,
marc

______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130



More information about the Forum mailing list