From: Frode Vatvedt Fjeld
Subject: Double let
Date: 
Message-ID: <2hd6oj2pvb.fsf@vserver.cs.uit.no>
This question was brought up on #lisp, and no-one seems to be
confident about the answer, so I'm hoping someone here can help.

What is the value (if any) of (let ((x 1) (x 2)) x)?

Reading the CLHS page on let doesn't make me any wiser, and
implementations seem to disagree wildly.

-- 
Frode Vatvedt Fjeld

From: Chris Gehlker
Subject: Re: Double let
Date: 
Message-ID: <BA12034E.24004%gehlker@fastq.com>
On 12/3/02 6:28 AM, in article ··············@vserver.cs.uit.no, "Frode
Vatvedt Fjeld" <······@cs.uit.no> wrote:

> This question was brought up on #lisp, and no-one seems to be
> confident about the answer, so I'm hoping someone here can help.
> 
> What is the value (if any) of (let ((x 1) (x 2)) x)?
> 
> Reading the CLHS page on let doesn't make me any wiser, and
> implementations seem to disagree wildly.

OpenMCL says it's 1 and Clisp says it's 2. I'm pretty confident it's between
0 and 3. :-)



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Michael Hudson
Subject: Re: Double let
Date: 
Message-ID: <7h3ptsjmcg2.fsf@pc150.maths.bris.ac.uk>
Chris Gehlker <·······@fastq.com> writes:

> On 12/3/02 6:28 AM, in article ··············@vserver.cs.uit.no, "Frode
> Vatvedt Fjeld" <······@cs.uit.no> wrote:
> 
> > This question was brought up on #lisp, and no-one seems to be
> > confident about the answer, so I'm hoping someone here can help.
> > 
> > What is the value (if any) of (let ((x 1) (x 2)) x)?
> > 
> > Reading the CLHS page on let doesn't make me any wiser, and
> > implementations seem to disagree wildly.
> 
> OpenMCL says it's 1 and Clisp says it's 2. I'm pretty confident it's between
> 0 and 3. :-)

CMUCL barfs -- which was my expectation.  Can't find any mention of it
in the hyperspec, though, which is a bit surprising.  Googling isn't
helping either.

Cheers,
M.

-- 
  Like most people, I don't always agree with the BDFL (especially
  when he wants to change things I've just written about in very 
  large books), ... 
         -- Mark Lutz, http://python.oreilly.com/news/python_0501.html
From: Geoffrey Summerhayes
Subject: Re: Double let
Date: 
Message-ID: <dI4H9.1701$2S1.516685@news20.bellglobal.com>
"Frode Vatvedt Fjeld" <······@cs.uit.no> wrote in message ···················@vserver.cs.uit.no...
> This question was brought up on #lisp, and no-one seems to be
> confident about the answer, so I'm hoping someone here can help.
>
> What is the value (if any) of (let ((x 1) (x 2)) x)?

42 :-)

> Reading the CLHS page on let doesn't make me any wiser, and
> implementations seem to disagree wildly.


It's undefined behaviour, the order of evaluation of the init forms is specified,
the order in which the assignments occur is implementation-dependant.

Doctor, Doctor, it hurts when I do this...

--
Geoff
From: Larry Clapp
Subject: Re: Double let
Date: 
Message-ID: <vtlisa.fhf.ln@127.0.0.1>
In article <·····················@news20.bellglobal.com>, Geoffrey Summerhayes wrote:
> "Frode Vatvedt Fjeld" <······@cs.uit.no> wrote in message ···················@vserver.cs.uit.no...
>> This question was brought up on #lisp, and no-one seems to be confident
>> about the answer, so I'm hoping someone here can help.
>>
>> What is the value (if any) of (let ((x 1) (x 2)) x)?
> 
> 42 :-)
> 
>> Reading the CLHS page on let doesn't make me any wiser, and implementations
>> seem to disagree wildly.
> 
> It's undefined behaviour, the order of evaluation of the init forms is
> specified, the order in which the assignments occur is
> implementation-dependant.
> 
> Doctor, Doctor, it hurts when I do this...

In case Frode doesn't get the reference, the cannonical response is "So don't
do that."

-- L



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
From: Mario S. Mommer
Subject: Re: Double let
Date: 
Message-ID: <fzadjn9f9o.fsf@cupid.igpm.rwth-aachen.de>
Larry Clapp <·····@theclapp.org> writes:
> > Doctor, Doctor, it hurts when I do this...
> 
> In case Frode doesn't get the reference, the cannonical response is "So don't
> do that."

Indeed. But what if such a let appears during macro expansion? OOUCH!!

Mario.
From: Geoffrey Summerhayes
Subject: Re: Double let
Date: 
Message-ID: <BW9H9.2287$2S1.558506@news20.bellglobal.com>
"Mario S. Mommer" <········@yahoo.com> wrote in message ···················@cupid.igpm.rwth-aachen.de...
> Larry Clapp <·····@theclapp.org> writes:
> > > Doctor, Doctor, it hurts when I do this...
> >
> > In case Frode doesn't get the reference, the cannonical response is "So don't
> > do that."
>
> Indeed. But what if such a let appears during macro expansion? OOUCH!!
>

Shouldn't happen often, the only times I can think of where this
would be a problem is in utility macros like Graham's WITH-GENSYMS:

(defmacro with-gensyms (syms &body body)
  `(let ,(mapcar #'(lambda (s)
                     `(,s (gensym)))
                 syms)
     ,@body))

Most macros are, or at least should be, designed to avoid this kind
of problem by using GENSYM or COPY-SYMBOL.

--
Geoff
From: JP Massar
Subject: Re: Double let
Date: 
Message-ID: <3decf64a.40245844@netnews.attbi.com>
On Tue, 3 Dec 2002 11:10:29 -0500, "Geoffrey Summerhayes"
<·············@hotmail.com> wrote:

>
>"Frode Vatvedt Fjeld" <······@cs.uit.no> wrote in message ···················@vserver.cs.uit.no...
>> This question was brought up on #lisp, and no-one seems to be
>> confident about the answer, so I'm hoping someone here can help.
>>
>> What is the value (if any) of (let ((x 1) (x 2)) x)?
>
>42 :-)
>
>> Reading the CLHS page on let doesn't make me any wiser, and
>> implementations seem to disagree wildly.
>
>
>It's undefined behaviour, the order of evaluation of the init forms is specified,
>the order in which the assignments occur is implementation-dependant.
>
 
Well, the hyperspec says that 'LET performs the bindings in parallel'

and that a binding is

'an association between a name and that which the name denotes'.

So we have an attempt here to bind the same name to two different
'denotations' IN PARALLEL, which I interpret as meaning 'semantically
equivalent as happening at the same time'

This would seem to be a logical impossibility (one cannot bind the
same thing to two different values simultaneously) and thus, whether
the hyperspec specifically says it is an error or not, should be
considered an error.  (Logical impossibilities being that kind of
beast...)
From: Pascal Costanza
Subject: Re: Double let
Date: 
Message-ID: <asjaju$8u$1@newsreader2.netcologne.de>
JP Massar wrote:
> On Tue, 3 Dec 2002 11:10:29 -0500, "Geoffrey Summerhayes"
> <·············@hotmail.com> wrote:
> 
> 
>>"Frode Vatvedt Fjeld" <······@cs.uit.no> wrote in message ···················@vserver.cs.uit.no...
>>
>>>This question was brought up on #lisp, and no-one seems to be
>>>confident about the answer, so I'm hoping someone here can help.
>>>
>>>What is the value (if any) of (let ((x 1) (x 2)) x)?
>>
>>42 :-)
>>
>>
>>>Reading the CLHS page on let doesn't make me any wiser, and
>>>implementations seem to disagree wildly.
>>
>>
>>It's undefined behaviour, the order of evaluation of the init forms is specified,
>>the order in which the assignments occur is implementation-dependant.
>>
> 
>  Well, the hyperspec says that 'LET performs the bindings in parallel'
> 
> and that a binding is
> 
> 'an association between a name and that which the name denotes'.
> 
> So we have an attempt here to bind the same name to two different
> 'denotations' IN PARALLEL, which I interpret as meaning 'semantically
> equivalent as happening at the same time'
> 
> This would seem to be a logical impossibility (one cannot bind the
> same thing to two different values simultaneously) and thus, whether
> the hyperspec specifically says it is an error or not, should be
> considered an error.  (Logical impossibilities being that kind of
> beast...)

One could superimpose the two bindings, and announce this as a first 
step towards an extension of Lisp for quantum computation. ;)


Pascal

-- 
Given any rule, however �fundamental� or �necessary� for science, there 
are always circumstances when it is advisable not only to ignore the 
rule, but to adopt its opposite. - Paul Feyerabend
From: JP Massar
Subject: Re: Double let
Date: 
Message-ID: <3ded4db9.62632571@netnews.attbi.com>
On Tue, 03 Dec 2002 23:18:47 +0100, Pascal Costanza <········@web.de>
wrote:
 
>> 
>> This would seem to be a logical impossibility (one cannot bind the
>> same thing to two different values simultaneously) and thus, whether
>> the hyperspec specifically says it is an error or not, should be
>> considered an error.  (Logical impossibilities being that kind of
>> beast...)
>
>One could superimpose the two bindings, and announce this as a first 
>step towards an extension of Lisp for quantum computation. ;)
>
 
I was going to put in a caveat to the effect of 'unless perhaps we
are within the quantum mechanical realm', but I decided that wasn't
necessary.

Obviously, I was wrong.

:-)
From: Kenny Tilton
Subject: Re: Double let
Date: 
Message-ID: <3DED68B3.5020707@nyc.rr.com>
JP Massar wrote:
> On Tue, 03 Dec 2002 23:18:47 +0100, Pascal Costanza <········@web.de>
> wrote:
>  
> 
>>>This would seem to be a logical impossibility (one cannot bind the
>>>same thing to two different values simultaneously) and thus, whether
>>>the hyperspec specifically says it is an error or not, should be
>>>considered an error.  (Logical impossibilities being that kind of
>>>beast...)
>>
>>One could superimpose the two bindings, and announce this as a first 
>>step towards an extension of Lisp for quantum computation. ;)
>>
> 
>  
> I was going to put in a caveat to the effect of 'unless perhaps we
> are within the quantum mechanical realm', but I decided that wasn't
> necessary.
> 
> Obviously, I was wrong.

No, making that observation would have changed everything. Then you 
would have been wrong. Now you are right.

:)

-- 

  kenny tilton
  clinisys, inc
  ---------------------------------------------------------------
""Well, I've wrestled with reality for thirty-five years, Doctor,
   and I'm happy to state I finally won out over it.""
                                                   Elwood P. Dowd
From: Brian Palmer
Subject: Re: Double let
Date: 
Message-ID: <0whn0nh9j7k.fsf@rescomp.Stanford.EDU>
······@alum.mit.edu (JP Massar) writes:

> On Tue, 03 Dec 2002 23:18:47 +0100, Pascal Costanza <········@web.de>
> wrote:
>  
> >> 
> >> This would seem to be a logical impossibility (one cannot bind the
> >> same thing to two different values simultaneously) and thus, whether
> >> the hyperspec specifically says it is an error or not, should be
> >> considered an error.  (Logical impossibilities being that kind of
> >> beast...)
> >
> >One could superimpose the two bindings, and announce this as a first 
> >step towards an extension of Lisp for quantum computation. ;)
> >
>  
> I was going to put in a caveat to the effect of 'unless perhaps we
> are within the quantum mechanical realm', but I decided that wasn't
> necessary.

Surprisingly enough. Perl supports quantum superpositions
(<http://search.cpan.org/author/LEMBARK/Quantum-Superpositions-1.05/lib/Quantum/Superpositions.pm>)
as well as quantum entanglement
(<http://search.cpan.org/author/AJGOUGH/Quantum-Entanglement-0.32/Entanglement.pm>).


which I had always dismissed as a curiousity, but it looks like
they're being moved into the core in Perl6. So it's quite possible
people will start using some quantum thinking in their lisp
programs =)

-- 
If you want divine justice, die.
                  -- Nick Seldon 
From: Espen Wiborg
Subject: Re: Double let
Date: 
Message-ID: <m3vg2b2on2.fsf@montgomery.empolis.no>
Frode Vatvedt Fjeld <······@cs.uit.no> writes:
> This question was brought up on #lisp, and no-one seems to be
> confident about the answer, so I'm hoping someone here can help.
> What is the value (if any) of (let ((x 1) (x 2)) x)?
> Reading the CLHS page on let doesn't make me any wiser, and
> implementations seem to disagree wildly.

My immediate take on this is that it should be an error; it is
equivalent to ((lambda (x x) x) 1 2), and repeating of parameter names
in a lambda list seems wrong.  However, a quick look at CLHS section
3.4 doesn't find anything to support this view, soI may be wrong.

CMUCL seems to agree with me, though:

* (let ((x 1) (x 2)) x)

In: LET ((X 1) (X 2))
  (LET ((X 1) (X 2))
    X)
Error: Repeated variable in lambda-list: X.

-- 
Espen Wiborg <·······@grumblesmurf.org>
Save a tree - disband an ISO working group today.
        -- seen in Jason Zions's .sig, ages ago
From: Pascal Costanza
Subject: Re: Double let
Date: 
Message-ID: <3DECB9AF.5040800@web.de>
Espen Wiborg wrote:
> Frode Vatvedt Fjeld <······@cs.uit.no> writes:
> 
>>This question was brought up on #lisp, and no-one seems to be
>>confident about the answer, so I'm hoping someone here can help.
>>What is the value (if any) of (let ((x 1) (x 2)) x)?
>>Reading the CLHS page on let doesn't make me any wiser, and
>>implementations seem to disagree wildly.
> 
> 
> My immediate take on this is that it should be an error; it is
> equivalent to ((lambda (x x) x) 1 2), and repeating of parameter names
> in a lambda list seems wrong.  However, a quick look at CLHS section
> 3.4 doesn't find anything to support this view, soI may be wrong.
> 
> CMUCL seems to agree with me, though:
> 
> * (let ((x 1) (x 2)) x)
> 
> In: LET ((X 1) (X 2))
>   (LET ((X 1) (X 2))
>     X)
> Error: Repeated variable in lambda-list: X.

I have tried something similar in LispWorks.

((lambda (x x) x) 2 3)
=> 3


Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: Frode Vatvedt Fjeld
Subject: Re: Double let
Date: 
Message-ID: <2h8yz72n1c.fsf@vserver.cs.uit.no>
Pascal Costanza <········@web.de> writes:

> ((lambda (x x) x) 2 3)
> => 3

It seems to me that lambda is more like let*, in that the variables to
the left are visible to default-forms for variables to the right. For
example:

  ((lambda (x &optional (y x)) y) 1) == 1.

So I don't think one can infer too much about let from lambda.

-- 
Frode Vatvedt Fjeld
From: JP Massar
Subject: Re: Double let
Date: 
Message-ID: <3decf4fe.39913817@netnews.attbi.com>
On Tue, 03 Dec 2002 14:55:13 +0100, Espen Wiborg
<·······@grumblesmurf.org> wrote:
 
>
>My immediate take on this is that it should be an error; it is
>equivalent to ((lambda (x x) x) 1 2),

Amusingly, given your comment, above, Corman Lisp produces:


(let ((x 1) (x 2)) x)
;;; Warning: Unused variable X in anonymous function
1
((lambda (x x) x) 1 2)
;;; Warning: Unused variable X in anonymous function
2

 
From: Kent M Pitman
Subject: Re: Double let
Date: 
Message-ID: <sfwn0nnj7av.fsf@shell01.TheWorld.com>
Frode Vatvedt Fjeld <······@cs.uit.no> writes:

> This question was brought up on #lisp, and no-one seems to be
> confident about the answer, so I'm hoping someone here can help.
> 
> What is the value (if any) of (let ((x 1) (x 2)) x)?
> 
> Reading the CLHS page on let doesn't make me any wiser, and
> implementations seem to disagree wildly.

I don't think you're allowed to repeat a variable in a binding list,
but I don't remember where it says that.  Maybe smh can use his
searchable spec and find that...

I think the restriction even restricts let*, btw, even though it's
not really necessary in that case.  Historically, I think the issue
was partly about separability of declarations. e.g., is 
 (let* ((x 1.3) (x (truncate x))) (declare (fixnum x)) x)
valid?
From: Roger Corman
Subject: Re: Double let
Date: 
Message-ID: <3ded4277.841747028@nntp.sonic.net>
The two variables named x are at the same scope, correct? It seems
that it should be an error to attempt to introduce two indentical
names to the same scope. It may not be spelled out in the spec, but it
seems like common sense.  ;-)  There are so many ambiguities caused by
this that I don't see how you could sort them out.

Roger

On Tue, 3 Dec 2002 18:17:44 GMT, Kent M Pitman <······@world.std.com>
wrote:

>Frode Vatvedt Fjeld <······@cs.uit.no> writes:
>
>> This question was brought up on #lisp, and no-one seems to be
>> confident about the answer, so I'm hoping someone here can help.
>> 
>> What is the value (if any) of (let ((x 1) (x 2)) x)?
>> 
>> Reading the CLHS page on let doesn't make me any wiser, and
>> implementations seem to disagree wildly.
>
>I don't think you're allowed to repeat a variable in a binding list,
>but I don't remember where it says that.  Maybe smh can use his
>searchable spec and find that...
>
>I think the restriction even restricts let*, btw, even though it's
>not really necessary in that case.  Historically, I think the issue
>was partly about separability of declarations. e.g., is 
> (let* ((x 1.3) (x (truncate x))) (declare (fixnum x)) x)
>valid?
>
From: Kenny Tilton
Subject: Re: Double let
Date: 
Message-ID: <3DED6815.20103@nyc.rr.com>
Roger Corman wrote:
> The two variables named x are at the same scope, correct? It seems
> that it should be an error to attempt to introduce two indentical
> names to the same scope. 

Itis not clear to me from the spec that there would be two variables. 
Sounds more like the same variable would be bound twice. The spec says 
the forms producing the values to be bound would be executed leftmost 
first, but then is silent on the order of the bindings:

" (let ((var1 init-form-1)
        (var2 init-form-2)
        ...

... evaluates the expressions init-form-1, init-form-2, and so on, in 
that order, saving the resulting values. Then all of the variables varj 
are bound to the corresponding values."

As an implementor I would feel free to bind in reverse order as well as 
forward order. I do not see this as an error but as "behavior undefined".

-- 

  kenny tilton
  clinisys, inc
  ---------------------------------------------------------------
""Well, I've wrestled with reality for thirty-five years, Doctor,
   and I'm happy to state I finally won out over it.""
                                                   Elwood P. Dowd
From: Steven M. Haflich
Subject: Re: Double let
Date: 
Message-ID: <3DEDA6E5.4070501@alum.mit.edu>
Kent M Pitman wrote:

> I don't think you're allowed to repeat a variable in a binding list,
> but I don't remember where it says that.  Maybe smh can use his
> searchable spec and find that...

I don't know of any such restriction, but I do recollect the
issue being discussed somewhere, "but I don't rememebr where.
or when."  I checked also in CLtL2, but didn't find anything.
Anyone who wants to try searching the ANS for himself can visit
www.franz.com, click on search, then Search the ANS...
[This thing is htdig.  I have a Lisp full-text search engine,
but it isn't released yet...]

> I think the restriction even restricts let*, btw, even though it's
> not really necessary in that case.  Historically, I think the issue
> was partly about separability of declarations. e.g., is 
>  (let* ((x 1.3) (x (truncate x))) (declare (fixnum x)) x)
> valid?

I don't agree about let*.  Under the definition of let*, there
is no ambiguity about the semantics of the code if a variable is
repeated, despite the ambiguity of _declarations_ at the head of
the binding form body.  There are some things that cannot be
expressed without such declarations, but it if hurts when you
use this odd syntax, then don't use this odd syntax.

What I really don't understand is why all you esteemed language
lawyers are so concerned about LET, but silent about the same
issue for PSETQ.  PSETF is explicit that the setting of variables
is done in "unpredictable order", but PSETQ is silent.