<br><br><div class="gmail_quote">On Tue, Mar 11, 2008 at 12:25 AM, Kevin Scaldeferri <<a href="mailto:kevin@scaldeferri.com">kevin@scaldeferri.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
On Mar 10, 2008, at 3:44 PM, Kevin Scaldeferri wrote:<br>
<br>
><br>
> On Mar 10, 2008, at 2:11 PM, Torbjorn Tornkvist wrote:<br>
><br>
>><br>
>> Perhaps a stupid question. Do LFE implement currying?<br>
>> If not, why?<br>
>><br>
>> I want currying... :-)<br>
>><br>
><br>
> Here's something I threw together in a couple minutes:<br>
><br>
> %% F({a,b}) -> F'(a,b)<br>
> curry(F, Arity) -><br>
> if<br>
> Arity =:= 1 -> fun(A) -> F({A}) end;<br>
> Arity =:= 2 -> fun(A,B) -> F({A,B}) end;<br>
> Arity =:= 3 -> fun(A,B,C) -> F({A,B,C}) end;<br>
> Arity =:= 4 -> fun(A,B,C,D) -> F({A,B,C,D}) end;<br>
> Arity =:= 5 -> fun(A,B,C,D,E) -> F({A,B,C,D,E}) end;<br>
> true -> throw(unsupported_arity)<br>
> end.<br>
><br>
<br>
</div>Should do slightly more browsing of the docs before posting :-). This<br>
is a slight improvement:<br>
<div class="Ih2E3d"><br>
%% F({a,b}) -> F'(a,b)<br>
</div>curry(F) -><br>
{arity, Arity} = erlang:fun_info(F, arity),<br>
<div class="Ih2E3d"> if<br>
Arity =:= 1 -> fun(A) -> F({A}) end;<br>
Arity =:= 2 -> fun(A,B) -> F({A,B}) end;<br>
Arity =:= 3 -> fun(A,B,C) -> F({A,B,C}) end;<br>
Arity =:= 4 -> fun(A,B,C,D) -> F({A,B,C,D}) end;<br>
Arity =:= 5 -> fun(A,B,C,D,E) -> F({A,B,C,D,E}) end;<br>
true -> throw(unsupported_arity)<br>
end.<br>
</div></blockquote><div><br>That's wrong I think. Function F will be always called with arity 1.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
</div><div><div></div><div class="Wj3C7c">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil