[erlang-questions] re cursive fun()

Zvi exta7@REDACTED
Sun Oct 5 17:38:31 CEST 2008


Otherwise, than passing the Fun as argument to itself, one can implement
recursive functions, using code, like this:

fact(0) -> 1;
fact(N) when N>0 ->
            {M,F,_A} = element(2,process_info(self(),current_function)),
            N * {M,F}(N-1).

But this doesn't work for funs, if there are was something like:

Fact = fun(0) -> 1;
               (N) when N>0 ->
                    Fun = element(2,process_info(self(),current_fun)),
                    N * Fun(N-1).

Zvi


deepblue_other wrote:
> 
> hello
> I have this going on
> 
> FunVar = 
>    fun() ->
>       ...
>       FunVar()
>    end.
> 
> so the compiler is complaining that FunVar is unbound at the place where
> its being used inside fun(); this makes sense, however Im wondering how to
> make this into a recursive function since there's no name to reference the
> function with. 
> 
> thanks
> 

-- 
View this message in context: http://www.nabble.com/recursive-fun%28%29-tp19820386p19825781.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list