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

Benjamin Sambale bsambale at gmx.de
Tue Sep 21 19:20:13 BST 2010


  I forgot to copy my reply to the list:

Thank you very much! It works.

Am 21.09.2010 12:51, schrieb Mathieu Dutour:
> 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
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>



More information about the Forum mailing list