Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can LET* reuse variables?

5 views
Skip to first unread message

Andrew Philpot

unread,
Oct 5, 1995, 3:00:00 AM10/5/95
to
Is code like (LET* ((A 1)
(A (+ A 2)))
...)
legal CL?

It sure seems like it should be to me, whether I interpret it via
CLtL2 or the ANSI spec, or consider representing it in terms of nested
LETs (how I usually think about it):

(LET ((A 1))
(LET ((A (+ A 2)))
...))

This might be a good way to write a macro transformer for the LET*
special form, and in fact it's close to what LUCID does, (LUCID goes
on to replace the LETs with their equivalent LAMBDAs:

((LAMBDA (A)
((LAMBDA (A) ...) (+ A 2)))
1)

However, one implementation (which will go nameless for now) includes
a macro-function definition of LET* which transforms it into something
like the following:

((LAMBDA (&optional (A 1) (A (+ A 2)))) ...)

Note that in the more general case, this is a clever trick: The syntax
allows for defaulting values and assigning sequentially. It avoids
the problem of deeply nested expressions (in case that's a compiler or
run-time consideration).

However, for this special case, it fails miserably, since you can't
reuse the same variable name in a lambda list.

Now I don't make a habit of reusing variable names in LET* in this
way, but I have encountered code which does, and I certainly could
imagine such code being automatically generated by a macro or other
code processing program.

Is such code in error, or is the implementation lacking?

--
---------------------------------------------------------------
Andrew Philpot USC Information Sciences Institute
phi...@isi.edu 4676 Admiralty Way
(310) 822-1511 ext 201 Marina del Rey, CA 90292-6695

Pierpaolo Bernardi

unread,
Oct 6, 1995, 3:00:00 AM10/6/95
to
Andrew Philpot (phi...@sungod.isi.edu) wrote:
: Is code like (LET* ((A 1)

: (A (+ A 2)))
: ...)
: legal CL?

Yes. It is definitely legal.


: However, one implementation (which will go nameless for now) includes


: a macro-function definition of LET* which transforms it into something
: like the following:

: ((LAMBDA (&optional (A 1) (A (+ A 2)))) ...)

I hope that you didn't paid any money for this one!


Erik Naggum

unread,
Oct 7, 1995, 3:00:00 AM10/7/95
to
[Andrew Philpot]

| Is code like (LET* ((A 1)
| (A (+ A 2)))
| ...)
| legal CL?

[Pierpaolo Bernardi]

| Yes. It is definitely legal.

hmmm. what is the precise semantics of this construct in the presence of
declarations of A? e.g. will a (declare (special a)) cause one of A's to
be special and one to have lexical scope, or will both be special?

I can't find anything in ANSI CL which would support the "definitely", but
it appears to be legal, while it appears not to be legal in `let'. I don't
see why there should be a difference between the two, or where it is
specified that there is such a difference.

#<Erik 3022029208>
--
"He [O. J. Simpson] is going to kill me, and he is going to get away with it."
-- Nicole Brown Simpson (1959-1994)

0 new messages