Bill Allombert on Wed, 22 Aug 2007 15:07:10 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

lexically-scoped variables for GP


Dear PARI-dev,

Following Karim advice, I have commited the patch for lexical variables
in GP. This means that you are advised to use my() instead of local
to take advantage of it.

Please report any problems!

Example explaining the difference between local() and my().

? f()=print(v)
? g(x)=local(v=x);f()
? h(x)=my(v=x);f()
? g(5)
5
? h(5)
v

Example of uses of my/local inside closures:
? for(i=1,5,my(z=i^2+1);print(z^2+1));z
5
26
101
290
677
%2 = z

Cheers,
Bill.