[erlang-questions] Recursion in the shell=impossible?

David Cabana <>
Tue Jun 17 05:07:19 CEST 2008


It can be done, but it requires a subtle technique, the use of the y
combinator.  Here's a link to a post from Bill Clementson which may shed
some light:
http://bc.tech.coop/blog/070611.html

2008/6/16 Circular Function <>:

> 6> Fac = fun(X) -> N * Fac(N-1).
> * 1: syntax error before: '.'
> 6> Fac = fun(X) -> N * Fac(N - 1).
> * 1: syntax error before: '.'
> 6> Fac = fun(X) -> N * fac(N - 1).
> * 1: syntax error before: '.'
> 6> fac = fun(X) -> N * fac(N - 1).
> * 1: syntax error before: '.'
>
> is it not possible to write recursive functions in the shell?
> i have to do that ina module?
> can i write functiosn any other way than making an anonymous one and
> assigning it to a variable?
> 6> Sq = fun(X) -> X*X end.
> #Fun<erl_eval..6.13229925>
> 7> Sq(12).
> 144
> 8>
>
> ------------------------------
> Låna pengar utan säkerhet.
> Sök och jämför hos Yahoo! Shopping.<http://shopping.yahoo.se/c-100390123-lan-utan-sakerhet.html?partnerId=96915014>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080616/dbbb4fcb/attachment.html>


More information about the erlang-questions mailing list