[GAP Forum] Argument values in function calls

Anvita anvita21 at gmail.com
Mon Aug 13 13:29:06 BST 2007


Dear Forum,

Could someone please explain to me why in some cases
a function call may result in a change of the argument's
value while in others it does not. (See in the two examples below
the behavior of the value of "a"). The chapter 4.10
of the manual says that for each argument of a function
GAP allocates a new variable. Doesn't it mean that
the initial variable's value should always remain intact?

Thank you,
Anvita

### Example 1 ###

gap> f1:=function(l)
> l[1]:=l[1]+1;
> return l;
> end;
function( l ) ... end
gap>
gap> a:=[1];
[ 1 ]
gap> b:=f1(a);
[ 2 ]
gap> a;
[ 2 ]

### Example 2 ###

gap> f2:=function(l)
> l:=l+1;
> return l;
> end;
function( l ) ... end
gap>
gap> a:=1;
1
gap> b:=f2(a);
2
gap> a;
1
-------------------------------


More information about the Forum mailing list