How to convert list to a function arguments in Erlang? -
let's have function of arity. , want feed corresponding list of numbers.
obviously, if have f/2 function , list l = [1,2], can this:
f(hd(l), hd(tl(l))). but how can make general? think, there should kind of easy conversion list arguments, don't know yet.
look @ apply/2 function. want.
> apply( fun (x,y) -> x+y end, [1,2]). 3 there apply/3 includes module of function too:
> apply( io, format , [ "~p, ~p", [1,2]]). 1, 2
Comments
Post a Comment