[erlang-questions] LFE - Lisp Flavoured Erlang released

Torbjorn Tornkvist tobbe@REDACTED
Tue Mar 11 09:04:54 CET 2008


Well, the notion that M:F/Arity is unique doesn't need to hold
if you're implementing your own language on top of Erlang core, or ?

As an example, look at my little Haskell-to-Erlang experiment:

 http://blog.tornkvist.org/blog.yaws?id=1190846785574003

As you can see, it is also possible to make user-defined guards
when you're rolling your own language on top of Erlang core.

Cheers, Tobbe


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.
> 
> %% F(a,b) -> F'({a,b})
> uncurry(F) ->
>      fun(Tuple) -> apply(F, tuple_to_list(Tuple)) end.
> 
> 
> A gross hack, to be sure, although I can't see how you could have any  
> hope to avoid having to specify an Arity to curry().  Maybe there's a  
> way to implement it less horribly, though.
> 
> BTW, did you actually mean that you want partial application?  Via a  
> similar process:
> 
> papply(F, Arity, Arg) ->
>      if
>          Arity =:= 1 -> fun()        -> F(Arg) end;
>          Arity =:= 2 -> fun(A)       -> F(Arg,A) end;
>          Arity =:= 3 -> fun(A,B)     -> F(Arg,A,B) end;
>          Arity =:= 4 -> fun(A,B,C)   -> F(Arg,A,B,C) end;
>          Arity =:= 5 -> fun(A,B,C,D) -> F(Arg,A,B,C,D) end;
>          true -> throw(unsupported_arity)
>      end.
> 
> 
> 
> 
> -kevin




More information about the erlang-questions mailing list