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:
>* Was this ever considered back in the early days?

    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  
 
 [ 3 post ] 

 Relevant Pages 

1. Anaphoric Lambda?

2. #'(lambda ... (lambda

3. (lambda ()) vs #'(lambda ())

4. no re-binding of nested-scope locals, no re-binding in lambda, no,,, {was Re: lambda)

5. Anaphoric macros and packages

6. anaphoric setf?

7. Anaphoric macros

8. Can global refs be freed from lambda-lifting ? ( was Is Lambda-lifting necessary ? )

9. (lambda (arg) (...)) vs (lambda args (...))

10. what diff #'(lambda...) to (lambda...)?

11. Subroutine, lambda abstraction, tacit form

12. ST equivalent of lambda functions?

 

 
Powered by phpBB® Forum Software