[GAP Forum] Create a list of functions in GAP

Ben Summers bensums at gmail.com
Wed Sep 11 20:51:15 BST 2013


F := List([1..5], i -> (n -> n + i));


On 11 September 2013 16:21, Le Van Luyen <lvluyen at gmail.com> wrote:

> Dear all,
>
> I want to create a list of functions in GAP and I have used the following
> code lines:
>
> gap> F:=[];
> gap> for i in [1..5] do
> >       F[i]:=function( n)
> >               return n+i;
> >       end;
> >       od;
>
> I expect the result will be: F[1](1)=2; F[2](1)=3; F[3](1)=4
>
> But, In GAP
>
> gap>F[1](1);
> 6
> gap>F[2](1);
> 6
> gap>F[3](1);
> 6
>
>  It looks like all functions of list A are the same.
>
> Could you give me a way to create a list of functions like that?
>
> Thank you very much.
>
> Bests,
>
> Luyen
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum
>


More information about the Forum mailing list