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

Re: Currying in Dylan?



On Fri, 19 Jan 2001 15:30:02 -0500 (EST), Chris Double <chris@double.co.nz>
wrote:

> Zeno <zenem@nospam.earthlink.net> writes:
> 
> > What about 'foldr' and 'foldl'?  Can one pass a function which takes
> > two parameters?  i.e.,
> > 
> >    foldr((+), 0, #(1, 2, 3));
> >       => 6
> > 
> > ...or...
> > 
> >    do( ((+), 1), #(1, 2, 3));
> >       => #(2, 3, 4)
> 
> Yes, with map for example you can do:
> 
>   map(\+, #(1,2,3), #(4,5,6));
>     => $0 = #(5, 7, 9)
> 
> Note that 'do' doesn't return anything. It's only used for side
> effects. You can also curry. Life the following:
> 
>   map(curry(\+, 1), #(1, 2, 3));
>     => $2 = #(2, 3, 4)

In FunDev's last days at Harlequin Keith Playford had a prototype extension
to FunDev that allowed you to say:

   map( \+( 1, _ ), #( 1, 2, 3 ) );

which I thought was neat.

__Jason


References: