[GAP Forum] Create a list of functions in GAP

Bill Allombert Bill.Allombert at math.u-bordeaux1.fr
Wed Sep 11 21:10:56 BST 2013


On Wed, Sep 11, 2013 at 11:34:58AM -0500, Robert Morse wrote:
> The value of the variable i is not bound at function definition.
> Rather, whatever i 's value at function execution is what is used.

Please excuse my curiosity as someone who wrote some computer algebra system
interpretor.
Are you saying that i is a global variable which is dynamicaly scoped ?

> After the loop the variable i has the value 5.  Hence calling each
> instance F[i] returns the same value.
> 
> You can accomplish what you want by writing a function that creates
> the function (binding the value i):
> 
> factory := function(i) return function(n) return n+i; end; end;

and there i is function parameter which is lexicaly scoped,
and functions are closed over lexicaly scoped variable ?

Cheers,
Bill.



More information about the Forum mailing list