Actually that can be shortened to MakeF2 := q->x->x+q;
> On 16 Apr 2015, at 23:26, Stephen Linton <steve.lin...@st-andrews.ac.uk> > wrote: > > This seems rather complicated compared to > > MakeF2 := function(q) > return x-> x+q: > end; > > Then you can use > > f0 := MakeF2(10); > f1 := MakeF2(20); > > Does this do what you need? > > Steve > > On 16 Apr 2015, at 23:19, Luca Giuzzi <luca.giu...@gmail.com> wrote: >> >> Dear Forum, >> is there a canonical way in gap to generate lexical closures for functions? >> The best I could come up with is something like >> >> MakeF:=function () >> local q; >> q := ValueGlobal( "q" ); >> return function(x) >> return x+q; >> end; >> end; >> >> which captures the value of the global value of q, so that >> q:=10; f0:=MakeF(); >> q:=20 f1:=MakeF(); >> gives >> f0(0)=10 and f1(0)=20 >> and it "sort of works" (and, at least for the cases I have in mind it >> might be enough) >> Still, I am asking if there might a better (or canonical) way to implement >> this? >> >> Regards, >> luca >> >> _______________________________________________ >> Forum mailing list >> Forum@mail.gap-system.org >> http://mail.gap-system.org/mailman/listinfo/forum > > > _______________________________________________ > Forum mailing list > Forum@mail.gap-system.org > http://mail.gap-system.org/mailman/listinfo/forum _______________________________________________ Forum mailing list Forum@mail.gap-system.org http://mail.gap-system.org/mailman/listinfo/forum