Anaphoric Lambda?
Author Message
Anaphoric Lambda?

[Snip -- about a recursive lambda definition]

Quote:
>* Why not add this to the interpreter/compiler? The Interpreter always
>knows which function it is currently applying...

While I don't know why this was left out of the system, I have
found such a capability to be unnecessary in my (brief)
experience with Common Lisp for the following reason:

Lambda expressions tend to exist so you can pass simple
"one-time" functions to other functions, and these other
functions will take care of the recursion for you (like
mapcar, reduce, remove-if, etc...).

So by their very nature, lambda expressions tend not to be
recursive, hence something like (self) is not needed.

This has all been in my experience, and keep in mind that
I program functionally, which means that all my iteration
is performed by higher order functions (like mapcar,
etc...) or by recursion (I don't use looping).

I do tend to use maps, reductions, and filters very heavily --
possibly too heavily, so keep this in mind.

[Snip]

Quote:

>Bill

--
Ahmed

To respond via email, send email to punkrock at cs dot uh dot edu

Mon, 11 Sep 2000 03:00:00 GMT
Anaphoric Lambda?

Hi everyone,

Quote:
>Paul Graham's book "On Lisp" has a macro that binds the variable self to
>the current function. This gives anonymous functions without recourse to
>labels. A recursive anonymous function calls itself::

I haven't read 'On Lisp', I'm more familiar with Scheme, and I'm not too
experienced in these matters, so I might not know what I'm talking about.
There; now my disclaimer's out of the way.
Is this macro syntactic sugar for the Y combinator?  For instance,
without using define, we can write factorial as:

(lambda (n)
((lambda (f)
(f f n))
(lambda (self x)
(if (= k 0)
1
(* x (self self (- x 1)))))))

Does Graham's macro do something like this?

Quote:

I think I read somewhere that, since Lisp was mostly dynamically scoped
in the early days, this issue was easier to deal with.  In dynamically
scoped Scheme, wouldn't the following simple program work?

(let ((fact (lambda (n)   ;not letrec or labels
(if (= n 0)
1
(* n (fact (- n 1)))))))
(fact 10))

Best regards,
Aaron

Mon, 11 Sep 2000 03:00:00 GMT
Anaphoric Lambda?

>Paul Graham's book "On Lisp" has a macro that binds the variable self to
>the current function. This gives anonymous functions without recourse to
>labels. A recursive anonymous function calls itself::
[...]
Is this macro syntactic sugar for the Y combinator?  For instance,

No.  The macro just uses LABELS (which corresponds to Scheme's LETREC,
roughly):

(defmacro alambda (parms &body body)

#'self))

; This code is copyright 1993 by Paul Graham, but anyone who wants
; to use the code in any nonprofit activity, or distribute free
; verbatim copies (including this notice), is encouraged to do so.

rthappe

PS:  Paul Graham's book code is available online.  E.g. as
ftp://ftp.cs.umn.edu//dept/users/gini/aicode/graham/onlisp.lisp

Wed, 13 Sep 2000 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages