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

datacompboy datacompboy@REDACTED
Sat Jun 2 17:19:47 CEST 2007


that's easy!

FibI = fun
  (X,_) when X<1 -> throw(badarith);
  (1,_) -> 1;
  (2, _) -> 1;
  (X,FibI) -> FibI(X-1,FibI)+FibI(X-2,FibI)
end,
Fib = fun(X) -> FibI(X, FibI) end,
Fib(10).


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