[clean-list] Recursion in Lambda Functions?
Pieter Koopman
pieter@cs.kun.nl
Tue, 09 Oct 2001 09:32:07 +0200
Hi Jay,
At 22:23 08-10-2001 -0600, Jay Kint wrote:
>Kind of a dumb question, but perhaps I've missed something? Is there some
>identifer like "self" or "this" that identifies the current context that can
>be used to recurse in a lambda function?
No. For a recursion you need the name of a function. Lambda functions are
functions without a name and hence cannot be recursive.
If you insist you can of course create a recursive lambda function using
the Y-combinator. If you are very precise the function it self is not
recursive. The recursion comes from the Y-combinator. Here is a simple example:
f = Y (\f x -> if (x==0) [] [x: f (x-1)])
Y f = f (Y f)
Start = f 2
This program produces the list [2,1].
Have fun,
Pieter Koopman