[erlang-questions] LFE - Lisp Flavoured Erlang released

Hynek Vychodil vychodil.hynek@REDACTED
Tue Mar 11 07:32:55 CET 2008


On Tue, Mar 11, 2008 at 12:25 AM, Kevin Scaldeferri <kevin@REDACTED>
wrote:

>
> On Mar 10, 2008, at 3:44 PM, Kevin Scaldeferri wrote:
>
> >
> > On Mar 10, 2008, at 2:11 PM, Torbjorn Tornkvist wrote:
> >
> >>
> >> Perhaps a stupid question. Do LFE implement currying?
> >> If not, why?
> >>
> >> I want currying... :-)
> >>
> >
> > Here's something I threw together in a couple minutes:
> >
> > %% F({a,b}) -> F'(a,b)
> > curry(F, Arity) ->
> >     if
> >         Arity =:= 1 -> fun(A)         -> F({A}) end;
> >         Arity =:= 2 -> fun(A,B)       -> F({A,B}) end;
> >         Arity =:= 3 -> fun(A,B,C)     -> F({A,B,C}) end;
> >         Arity =:= 4 -> fun(A,B,C,D)   -> F({A,B,C,D}) end;
> >         Arity =:= 5 -> fun(A,B,C,D,E) -> F({A,B,C,D,E}) end;
> >         true -> throw(unsupported_arity)
> >     end.
> >
>
> Should do slightly more browsing of the docs before posting :-).  This
> is a slight improvement:
>
> %% F({a,b}) -> F'(a,b)
> curry(F) ->
>     {arity, Arity} = erlang:fun_info(F, arity),
>      if
>         Arity =:= 1 -> fun(A)         -> F({A}) end;
>         Arity =:= 2 -> fun(A,B)       -> F({A,B}) end;
>         Arity =:= 3 -> fun(A,B,C)     -> F({A,B,C}) end;
>         Arity =:= 4 -> fun(A,B,C,D)   -> F({A,B,C,D}) end;
>         Arity =:= 5 -> fun(A,B,C,D,E) -> F({A,B,C,D,E}) end;
>         true -> throw(unsupported_arity)
>     end.
>

That's wrong I think. Function F will be always called with arity 1.


> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080311/4cf55e6a/attachment.htm>


More information about the erlang-questions mailing list