From: Karol Skocik
Subject: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <1159451585.361549.266980@e3g2000cwe.googlegroups.com>
Hi,
  I have just read this article:

http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requestid=71496

and in the section "Impact of Logic", I saw this :

Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
Sussman, 1975; http://www.schemers .org/).

I am a happy CL lambda user, and can't find something wrong in CL's
lambda...

Could some functional guru explain me what they meant?

Thanks, 
  Karol

From: Barry Margolin
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <barmar-B90C85.10485828092006@comcast.dca.giganews.com>
In article <························@e3g2000cwe.googlegroups.com>,
 "Karol Skocik" <············@gmail.com> wrote:

> Hi,
>   I have just read this article:
> 
> http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requ
> estid=71496
> 
> and in the section "Impact of Logic", I saw this :
> 
> Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
> Sussman, 1975; http://www.schemers .org/).
> 
> I am a happy CL lambda user, and can't find something wrong in CL's
> lambda...
> 
> Could some functional guru explain me what they meant?

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))

-- 
Barry Margolin, ······@alum.mit.edu
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 ***
From: Duane Rettig
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <o0ven89fqi.fsf@franz.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <························@e3g2000cwe.googlegroups.com>,
>  "Karol Skocik" <············@gmail.com> wrote:
>
>> Hi,
>>   I have just read this article:
>> 
>> http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requ
>> estid=71496
>> 
>> and in the section "Impact of Logic", I saw this :
>> 
>> Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
>> Sussman, 1975; http://www.schemers .org/).
>> 
>> I am a happy CL lambda user, and can't find something wrong in CL's
>> lambda...
>> 
>> Could some functional guru explain me what they meant?
>
> 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): 

Looks like a CPS issue to me, not a lambda issue (at least directly).

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Barry Margolin
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <barmar-93A890.11531428092006@comcast.dca.giganews.com>
In article <··············@franz.com>, Duane Rettig <·····@franz.com> 
wrote:

> Looks like a CPS issue to me, not a lambda issue (at least directly).

Since CL doesn't have continuations, I'm not sure there's really much of 
a distinction.  Lambda is the only way to make a closure, and the point 
is that closures can't be used to re-enter a control context that has 
been exited.

-- 
Barry Margolin, ······@alum.mit.edu
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 ***
From: Duane Rettig
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <o0psdfdiuy.fsf@franz.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <··············@franz.com>, Duane Rettig <·····@franz.com> 
> wrote:
>
>> Looks like a CPS issue to me, not a lambda issue (at least directly).
>
> Since CL doesn't have continuations, I'm not sure there's really much of 
> a distinction.  Lambda is the only way to make a closure, and the point 
> is that closures can't be used to re-enter a control context that has 
> been exited.

Yes, of course.  My comment is directed toward the possible
interpretation of a statement like "something is wrong with CL lambda"
as being something revelationary; instead it falls under the subset of
things not specified by CL because CL doesn't specify continuations/CPS.

-- 
Duane Rettig    ·····@franz.com    Franz Inc.  http://www.franz.com/
555 12th St., Suite 1450               http://www.555citycenter.com/
Oakland, Ca. 94607        Phone: (510) 452-2000; Fax: (510) 452-0182   
From: Sacha
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <XSRSg.101055$iq2.1403931@phobos.telenet-ops.be>
>> 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 
From: Barry Margolin
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <barmar-3ADB23.12084828092006@comcast.dca.giganews.com>
In article <························@phobos.telenet-ops.be>,
 "Sacha" <··@address.spam> 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, ······@alum.mit.edu
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 ***
From: Ralf Mattes
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <pan.2006.09.28.15.18.29.618095@mh-freiburg.de>
On Thu, 28 Sep 2006 10:48:58 -0400, Barry Margolin wrote:

> In article <························@e3g2000cwe.googlegroups.com>,
>  "Karol Skocik" <············@gmail.com> wrote:
> 
>> Hi,
>>   I have just read this article:
>> 
>> http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requ
>> estid=71496
>> 
>> and in the section "Impact of Logic", I saw this :
>> 
>> Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
>> Sussman, 1975; http://www.schemers .org/).
>> 
>> I am a happy CL lambda user, and can't find something wrong in CL's
>> lambda...
>> 
>> Could some functional guru explain me what they meant?
> 
> 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))))
> 

Shouldn't this read:


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

Form file:///usr/share/doc/hyperspec/Body/s_tagbod.htm:

  ... If at any time there are no remaining statements, 
  tagbody returns nil.


 Cheers, Ralf Mattes


> (funcall (make-bad-closure))
From: Rob Warnock
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <YKydnRz-ypA5MoHYnZ2dnUVZ_tqdnZ2d@speakeasy.net>
Barry Margolin <······@alum.mit.edu> wrote:
+---------------
|  "Karol Skocik" <············@gmail.com> wrote:
| > and in the section "Impact of Logic", I saw this :
| > Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
| > Sussman, 1975; http://www.schemers .org/).
| > I am a happy CL lambda user, and can't find something wrong in CL's
| > lambda...
| > Could some functional guru explain me what they meant?
| 
| 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.
+---------------

Besides the scope-of-control (continuations) issue you mentioned,
below is another, of even greater impact to newbies.

+---------------
| Although CL has lexical extent for variable bindings...
+---------------

Well, yes... and no. As you know like the back of your hand, but
Karol might not, CL:LAMBDA does indeed provide lexical scope for
variable bindings which are either new or which shadow previous
lexical bindings, but provides *dynamic* ("special") semantics for
variables which already have lexically-apparent special declarations:

    > (defmacro show ((&optional (where #\space)) &rest forms)
        `(format t "~&·····@{~a = ~s~:^,  ~}.~%"
		   ',where
                   ,@(loop for form in forms collect
                       `(list ',form ,form))))

    SHOW
    > (defvar a 12)

    A
    > (defun a () a)

    A
    > (let ((b 34))
	(flet ((b () b))
	  (show (before) a (a) b (b))
	  (funcall (lambda (a b)
		     (show (lambda) a (a) b (b)))
		   56
		   78)
	  (show (after) a (a) b (b))
	  nil))

    BEFORE  A = 12,  (A) = 12,  B = 34,  (B) = 34.
    LAMBDA  A = 56,  (A) = 56,  B = 78,  (B) = 34.
    AFTER   A = 12,  (A) = 12,  B = 34,  (B) = 34.
    NIL
    > 

[Karol, if it's not obvious, look at the value of (A) in the LAMBDA line.]

Most Schemers consider this to be evil, and think that dynamic bindings
should always be made quite explicit, e.g., by using FLUID-LET or equiv.

On the contrary, CL'ers consider this feature to be extremely useful[1]
albeit dangerously error-prone, fortunately made essentially harmless
by ALWAYS obeying the surrounding-asterisks naming convention for special
variables, e.g., *VAR*. [Ditto the +CONST+ convention for constants.]


-Rob

[1] For example: (LET ((*PACKAGE* XYZ-PKG)) (READ)).

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Pascal Bourguignon
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <87psdguknc.fsf@thalassa.informatimago.com>
"Karol Skocik" <············@gmail.com> writes:

> Hi,
>   I have just read this article:
>
> http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requestid=71496
>
> and in the section "Impact of Logic", I saw this :
>
> Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
> Sussman, 1975; http://www.schemers .org/).
>
> I am a happy CL lambda user, and can't find something wrong in CL's
> lambda...
>
> Could some functional guru explain me what they meant?

COMMON-LISP:LAMBDA is ok.  
Common Lisp is a dialect of Lisp which got lambda right too.


The lambda in LISP 1.5 and before had some problems.  Namely, it
didn't create a lexical scope, like in Scheme and Common Lisp, 
nor a closure. 

See:   http://www-formal.stanford.edu/jmc/history/lisp/node4.html

     d. Free variables. In all innocence, James R. Slagle programmed
     the following LISP function definition and complained when it
     didn't work right:

        The object of the function is to find a subexpression of x
        satisfying p[x] and return f[x]. If the search is
        unsuccessful, then the continuation function u[] of no
        arguments is to be computed and its value returned. The
        difficulty was that when an inner recursion occurred, the
        value of car[x] wanted was the outer value, but the inner
        value was actually used. In modern terminology, lexical
        scoping was wanted, and dynamic scoping was obtained. 


The lambda of emacs lisp is still 'broken'.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Logiciels libres : nourris au code source sans farine animale."
From: Karol Skocik
Subject: Re: What's wrong with Common Lisp's lambda ?
Date: 
Message-ID: <1159472393.536383.44530@i42g2000cwa.googlegroups.com>
Thank for reply, I was scared a bit :)

Pascal Bourguignon wrote:
> "Karol Skocik" <············@gmail.com> writes:
>
> > Hi,
> >   I have just read this article:
> >
> > http://www.ddj.com/184404384;jsessionid=KLMB3AY1Q0DHQQSNDLPCKH0CJUNN2JVN?_requestid=71496
> >
> > and in the section "Impact of Logic", I saw this :
> >
> > Scheme, a dialect of Lisp which got lambda right (Guy Steele and Gerald
> > Sussman, 1975; http://www.schemers .org/).
> >
> > I am a happy CL lambda user, and can't find something wrong in CL's
> > lambda...
> >
> > Could some functional guru explain me what they meant?
>
> COMMON-LISP:LAMBDA is ok.
> Common Lisp is a dialect of Lisp which got lambda right too.
>
>
> The lambda in LISP 1.5 and before had some problems.  Namely, it
> didn't create a lexical scope, like in Scheme and Common Lisp,
> nor a closure.
>
> See:   http://www-formal.stanford.edu/jmc/history/lisp/node4.html
>
>      d. Free variables. In all innocence, James R. Slagle programmed
>      the following LISP function definition and complained when it
>      didn't work right:
>
>         The object of the function is to find a subexpression of x
>         satisfying p[x] and return f[x]. If the search is
>         unsuccessful, then the continuation function u[] of no
>         arguments is to be computed and its value returned. The
>         difficulty was that when an inner recursion occurred, the
>         value of car[x] wanted was the outer value, but the inner
>         value was actually used. In modern terminology, lexical
>         scoping was wanted, and dynamic scoping was obtained.
>
>
> The lambda of emacs lisp is still 'broken'.
>
> --
> __Pascal Bourguignon__                     http://www.informatimago.com/
> 
> "Logiciels libres : nourris au code source sans farine animale."