Charles Greathouse on Mon, 17 Nov 2014 21:52:03 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: New GP function self() for recursive anonymous functions |
Dear PARI developers,
I have added a GP function self() which allow to write recursive anonymous
functions:
? (n->if(n==0,1,n*self()(n-1)))(5)
%1 = 120
self() returns the calling function or closure.
This is useful to avoid using global variables when using parallel GP:
For example
my(f(n)=if(n==0,1,n*self()(n-1))); parapply(f,[100..200])
is valid but
f(n)=if(n==0,1,n*f()(n-1))
parapply(f,[100..200])
is not.
Please tell me if it is useful to you.
Cheers,
Bill.