[erlang-questions] re cursive fun()

deepblue_other cktgatb@REDACTED
Mon Oct 6 17:34:21 CEST 2008


the example I gave was not suppose to be a practical one, I just wanted to
ask how to recursively call a anonymous function...

Richard O'Keefe wrote:
> 
> On 5 Oct 2008, at 4:19 pm, deepblue_other wrote:
>> I have this going on
>>
>> FunVar =
>>   fun() ->
>>      ...
>>      FunVar()
>>   end.
>>
> Shouldn't this go in a FAQ somewhere?
> Maybe it belongs in the reference manual.
> 
> The quick answer is that if you need a recursive
> function, why not write a recursive function in the
> usual way?
> 
> There's something particularly nasty about this
> example.  One normally proves (or at any rate
> argues with vigourously waving hands for) the
> termination of a recursive function by showing
> that some non-negative measure of its arguments
> strictly decreases on each recursive call, but
> this function has no arguments.  I think we need
> to see more of it.
> 
> The long answer is that you can always do
> 
> 	Rec = fun (Self, Args) ->
> 		....
> 		Self(Self, Args')
> 	      end,
> 	Foo = fun (Args) -> Rec(Rec, Args) end,
> 
> It's possible, but you are working against the
> grain of the language, and there is most likely
> a better way to achieve your goals.
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 

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




More information about the erlang-questions mailing list