Bill Allombert on Wed, 15 Jan 2014 23:35:45 +0100


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

unline for parallel GP


On Mon, Oct 14, 2013 at 05:05:51PM +0200, Bill Allombert wrote:
> On Sun, Oct 13, 2013 at 02:28:25PM +0200, Bill Allombert wrote:
> > Dear PARI developers,
> > 
> > An new declaration is available:
> > inline(var)
> > This declares that var should be inlined in each functions, with the value
> > of var at the time the function is created.
> > This allows to create functions that are not stored in global variables,
> > which is necessar for parallel code.
> 
> I want to clarify that I see inline() as a work-around for a syntactic 
> limitation in the GP language.

For what it is worth, I have created a branch bill-uninline which adds a 
declaration unline() which allow to forget all the inline() variables.
So you can do in a GP file:

inline(fun);
fun(x)=x^2;
pub(N)=parvector(N,i,fun(i))
uninline()

and at the end, only pub() will be declared.

I am also considering adding self() which would return the calling closure.
This would allow to write simply-recursive anonymous function without using 
the Y combinator f->x->f(f,x). So instead of
my(Y=f->x->f(f,x), g(fun,x)=if(x==0,1,x*fun(fun,x-1)), fact=Y(g)); fact(10)
one could do
my(fact=x->if(x==0,1,x*self()(x-1)));fact(10)

But I only know how to implement self by using the debugger trace (to
skip inline closures).

Cheers,
Bill.