[erlang-questions] Auto generated functions

Zvi exta7@REDACTED
Wed Feb 6 23:03:11 CET 2008


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


Christian S wrote:
> 
> On Feb 4, 2008 11:39 PM, Attila Babo <babo.online@REDACTED> wrote:
>> I wrote a simple Y combinator to deal with tail-recursive anonymous
>> functions. There are several showcase implementations for Erlang
>> already, but for practical purposes you need to deal with arity. Here
>> is my code with examples, I'm looking for a way to avoid this
>> boilerplate code. For practical reasons it's OK to generate it up to a
>> point by hand or use a single tuple as a parameter, but I'm looking
>> for "nicer" solution. Any suggestions?
> 
> That's the way its done. Only improvement would be to use the
> erlang:is_funciton/2 guard. But that is not likely what you were looking
> for.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 

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




More information about the erlang-questions mailing list