Re: What's wrong with Common Lisp's lambda ?
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 12:08:48 -0400
In article <XSRSg.101055$iq2.1403931@xxxxxxxxxxxxxxxxxxxxx>,
"Sacha" <no@xxxxxxxxxxxx> wrote:
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 ?
Instead of returning a closure from inside the tagbody, you return one
that CONTAINS the tagbody, enters it, and jumps to the label. But I'm
having a hard time coming up with a good example.
More likely, though, you use an algorithm that doesn't require this in
the first place. Similar to what you do when you use languages that
don't have lexical closures.
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- References:
- What's wrong with Common Lisp's lambda ?
- From: Karol Skocik
- Re: What's wrong with Common Lisp's lambda ?
- From: Barry Margolin
- Re: What's wrong with Common Lisp's lambda ?
- From: Duane Rettig
- Re: What's wrong with Common Lisp's lambda ?
- From: Sacha
- What's wrong with Common Lisp's lambda ?
- Prev by Date: Re: What's wrong with Common Lisp's lambda ?
- Next by Date: Re: What's wrong with Common Lisp's lambda ?
- Previous by thread: Re: What's wrong with Common Lisp's lambda ?
- Next by thread: Re: What's wrong with Common Lisp's lambda ?
- Index(es):
Relevant Pages
|