[erlang-questions] calling fun() from fun()

datacompboy <>
Sat Jun 2 17:19:47 CEST 2007


that's easy!

FibI = fun
&nbsp; &#40;X,_&#41; when X<1 -> throw&#40;badarith&#41;;
&nbsp; &#40;1,_&#41; -> 1;
&nbsp; &#40;2, _&#41; -> 1;
&nbsp; &#40;X,FibI&#41; -> FibI&#40;X-1,FibI&#41;+FibI&#40;X-2,FibI&#41;
end,
Fib = fun&#40;X&#41; -> FibI&#40;X, FibI&#41; end,
Fib&#40;10&#41;.


it produce correct result -- 55.
So, you just should pass it to itself, and if you must use one-arg fun (for example, to pass it to somewhere), make additional fun that will call real fun with additional arg.
--
--- suicide proc near\n call death\n suicide endp
_________________________________________________________
Post sent from http://www.trapexit.org


More information about the erlang-questions mailing list