Re: What's wrong with Common Lisp's lambda ?



Common Lisp adopted some features of Scheme's lambda, so it doesn't have
as many problems as earlier dialects of Lisp. But there are still
holes. Although CL has lexical extent for variable bindings, it only
has dynamic extent for control bindings. So you can't do:

(defun make-bad-closure ()
(tagbody
label
(print 'got-here)
(lambda () (go label))))

(funcall (make-bad-closure))

Your code has a bug in it; tagbody returns nil, not the lambda.
If we fix that, and execute it piecemeal, then it becomes clear why
CL didn't take this particular aspect of Scheme:

CL-USER(1): (defun make-bad-closure ()
(tagbody
label
(print 'got-here)
(return-from make-bad-closure (lambda () (go label)))))
MAKE-BAD-CLOSURE
CL-USER(2): (make-bad-closure)

GOT-HERE
#<Interpreted Closure (:INTERNAL MAKE-BAD-CLOSURE) @ #x4071fe7a>
CL-USER(3): (funcall *)
Error: Cannot go to LABEL, its body has been exited.
[condition type: CONTROL-ERROR]

Restart actions (select using :continue):
0: Return to Top Level (an "abort" restart).
1: Abort entirely from this (lisp) process.
[1] CL-USER(4):


This raises the question : how would you do such thing using common lisp ?

Sacha


.



Relevant Pages

  • Re: Whats wrong with Common Lisps lambda ?
    ... as many problems as earlier dialects of Lisp. ... Although CL has lexical extent for variable bindings, ... Your code has a bug in it; tagbody returns nil, ...
    (comp.lang.lisp)
  • Re: lisp equivalent to c++ continue
    ... the same as a goto to a hidden label: ... In Lisp terms, ... The symbol NIL can be used to name blocks. ... > Should I be coding in a different way that doesn't require this keyword? ...
    (comp.lang.lisp)
  • Re: Lisp an abstraction layer?
    ... > field of business application. ... We should label our products with a big: ... and speak of lisp only within the knowledgable circle... ... -- Robert Heinlein ...
    (comp.lang.lisp)