[erlang-questions] Automatic currying

Siraaj Khandkar <>
Sat May 2 06:22:41 CEST 2015


On 4/30/15 7:45 PM, Pierre Fenoll wrote:
> I'd like to have a shorthand syntax:
>
> 1> Print = fun io:format("lookee here: ~p\n")/1.
> #Fun<function.0.2345234>
> 2> Print([ stuff ]).
> lookee here: stuff
> ok
> 3>
>
> Print would actually be sugar for
> Print = fun (X) -> io:format("lookee here: ~p\n", X) end.
> with all the rules concerning funs applying in the same way.

Maybe like this:

     1>
     1> Print = function:curry(fun (Prefix, Term) -> io:format("~s~p~n", 
[Prefix, Term]) end).
     #Fun<function.0.4634292>
     2>
     2> PrintNaked = Print("").
     #Fun<function.0.4634292>
     3> PrintLookee = Print("lookee here: ").
     #Fun<function.0.4634292>
     4>
     4> PrintNaked(queue:new()).
     {[],[]}
     ok
     5>
     5> PrintLookee(queue:new()).
     lookee here: {[],[]}
     ok
     6>


More information about the erlang-questions mailing list