[GAP Forum] Bug in Add (list function)?

Mathieu Dutour Mathieu.Dutour at ens.fr
Tue Sep 21 11:51:34 BST 2010


This is because when you add the element e, you actually add
a pointer to it. Hence you change the value but the pointer
does not change.

The trick is to do
Add(L, ShallowCopy(e));
which really does the addition that you want.

>> Dear GAP Forum,
>> 
>> consider this small GAP code (I hope it is minimal somehow):
>> 
>> L:=[];
>> e:=[1];
>> for s in [[1],[0]] do
>>  e[1]:=s[1];
>>  Add(L,e);
>> od;
>> 
>> After that the list L should be [ [ 1 ], [ 0 ] ].  However GAP gives [ [ 
>> 0 ], [ 0 ] ]. I'm not quite sure if this is a bug. It seems to me that 
>> the Add function only adds a pointer or something similar. Note that the 
>> code works as expected if one uses e:=1 and so on (without additional 
>> square brackets). By the way I'm using GAP 4.4.12.
>> 
>> Thanks for clarification,
>> Benjamin Sambale
>> 
>> _______________________________________________
>> Forum mailing list
>> Forum at mail.gap-system.org
>> http://mail.gap-system.org/mailman/listinfo/forum



More information about the Forum mailing list