[erlang-questions] Auto generated functions

Zvi exta7@REDACTED
Thu Feb 21 15:20:21 CET 2008


In Javascript, unlike Erlang, anonymous function can call itself, without
using Y-combinator tricks.
Does it mean that JS is more functional than Erlang:

factorial = function(n){ return (n==0) ? 1 : n*arguments.callee(n-1); };

Factorial = fun(0) -> 1;
                   (N) -> N*???(N-1).

Zvi


Zvi wrote:
> 
> Y-combinator is cool, but I'm just currious why Erlang doesn't have some
> mechanism allowing fun to reference to itself (doesn't mutter if it's
> named or annonymous fun), same way as every process can get it's own PID
> using self(), i.e. (here I using this() to reference to function from
> inside):
> 
> Len = fun([]) -> 0;
>              ([_|T]) -> this()(T)+1 end.
> 
> Is there something in BEAM instruction set, that preventing from
> implementing this?
> 
> thanks,
> Zvi
> 

-- 
View this message in context: http://www.nabble.com/Auto-generated-functions-tp15279499p15612426.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list