Bill Allombert on Tue, 09 Dec 2014 19:25:12 +0100


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

Re: memoize.gp


On Tue, Dec 09, 2014 at 07:10:59PM +1100, Kevin Ryde wrote:
> I had a go at a generic memoize to wrap functions, including
> possibly anonymous functions.  It started as a way to write a
> few recurrences in a simple-minded way, then got a bit carried
> away.  The cutest bit is that because it can be applied to an
> existing function you can experiment with memory vs time for
> possibly re-used values.
> 
> http://user42.tuxfamily.org/pari-memoize/index.html

Hello Kevin,
thanks for your contribution!

I think your code could be simplified by using
direct access to t_CLOSURE instead of using strings.

You can access the number of arguments of a t_CLOSURE with
install(closure_arity,"lG","arity")
you can also use component():

? f=x->x^2+1
%1 = (x)->x^2+1
? component(f,5)
%2 = ["x","x^2+1"]

Cheers,
Bill.