Bill Allombert on Sat, 25 Apr 2020 17:03:40 +0200


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

new branch bill-closure-context


Dear PARI developers,

I have created a new git branch 'bill-closure-context'
which change the way closures contexts are generated,
while preserving backward compatibility.

In the following example, with the master branch:

? my(smallstuff=[1,2,3],bigstuff=vector(1000,i,i));f(i)=smallstuff[i];
? sizebyte(f)
%4 = 32520

This is because f include a copy of bigstuff.

In the branch

? my(smallstuff=[1,2,3],bigstuff=vector(1000,i,i));f(i)=smallstuff[i];
? sizebyte(f)
%2 = 512
? f
%3 = (i)->my(smallstuff=[1,2,3],bigstuff);smallstuff[i]

The compiler now detects that the value of bigstuff is not accessible by
f, so it does not store it in f. However it still lets the variable
declaration.

This mechanism should fix a number of usability issues with closures.

However the code is not well-tested, so if you have code that make heavy
use of closures, please test.

Cheers,
Bill