From: Peter Seibel
Subject: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <m31xia68ch.fsf@javamonkey.com>
That is, does `(...) always get read as code that conses up a new
list? 2.4.6 says:

  The constructed copy of the template might or might not share list
  structure with the template itself.

I take that to mean that the outer most level the list produced by the
backquoted expression is, well, a "constructed copy of the template"
even if it happens to share structure with subelements of the
template. Thus this is perfectly well defined:

  (loop repeat 10 nconcing `(x y))

while this is undefined:

  (loop repeat 10 nconcing '(x y))

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp

From: Barry Margolin
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <barmar-8B40C6.21532813082004@comcast.dca.giganews.com>
In article <··············@javamonkey.com>,
 Peter Seibel <·····@javamonkey.com> wrote:

> That is, does `(...) always get read as code that conses up a new
> list? 2.4.6 says:
> 
>   The constructed copy of the template might or might not share list
>   structure with the template itself.
> 
> I take that to mean that the outer most level the list produced by the
> backquoted expression is, well, a "constructed copy of the template"
> even if it happens to share structure with subelements of the
> template. Thus this is perfectly well defined:

I disagree.  I don't think any distinction is made between the outermost 
level and the nested levels -- it's all just one template.  The result 
of the backquote might share structure with any part of that, where 
feasible (see the other response for an example of parts that can't 
feasibly share).

> 
>   (loop repeat 10 nconcing `(x y))
> 
> while this is undefined:
> 
>   (loop repeat 10 nconcing '(x y))

I think they can both expand into the same code.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Peter Seibel
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <m3n00v10wo.fsf@javamonkey.com>
Barry Margolin <······@alum.mit.edu> writes:

> In article <··············@javamonkey.com>,
>  Peter Seibel <·····@javamonkey.com> wrote:
>
>> That is, does `(...) always get read as code that conses up a new
>> list? 2.4.6 says:
>> 
>>   The constructed copy of the template might or might not share list
>>   structure with the template itself.
>> 
>> I take that to mean that the outer most level the list produced by the
>> backquoted expression is, well, a "constructed copy of the template"
>> even if it happens to share structure with subelements of the
>> template. Thus this is perfectly well defined:
>
> I disagree. I don't think any distinction is made between the
> outermost level and the nested levels -- it's all just one template.
> The result of the backquote might share structure with any part of
> that, where feasible (see the other response for an example of parts
> that can't feasibly share).

Yeah, I was afraid someone was going to say something like that. It's
a pity, it seems, that backquote isn't just defined to always generate
new list structure (modulo use of ,.). Then all Lisp book authors who
are tempted to use '(1 2 3) instead of (list 1 2 3) because it's more
concise could use `(1 2 3) and be just as concise without incurring
the wrath of Kenny by misleading their readers into thinking '(1 2 3)
is a good way to make a list in an expression like:

  (nconc '(1 2 3) '(4 5 6))

Also that would mean backquote could/would get introduced much
earlier, outside the context of macros as just a shorthand way of
building up lists. But if `(x y z) is possibly going to be equivalent
to '(x y z) it's a lot more complex to explain when it will generate
new list structure and when it won't so it can't be used this way--it
needs to be reserved for later on when folks have half a chance of
understanding what things like "new list structure" means.

Oh well.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Marcin 'Qrczak' Kowalczyk
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <pan.2004.08.16.19.36.28.187711@knm.org.pl>
On Mon, 16 Aug 2004 16:55:11 +0000, Peter Seibel wrote:

> It's a pity, it seems, that backquote isn't just defined to always
> generate new list structure (modulo use of ,.). Then all Lisp book
> authors who are tempted to use '(1 2 3) instead of (list 1 2 3) because
> it's more concise could use `(1 2 3) and be just as concise

OTOH if the list is used in a functional style (not mutated and not
compared for identity), its duplication would be a wasted effort.

-- 
   __("<         Marcin Kowalczyk
   \__/       ······@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/
From: Peter Seibel
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <m3hdr2242j.fsf@javamonkey.com>
Marcin 'Qrczak' Kowalczyk <······@knm.org.pl> writes:

> On Mon, 16 Aug 2004 16:55:11 +0000, Peter Seibel wrote:
>
>> It's a pity, it seems, that backquote isn't just defined to always
>> generate new list structure (modulo use of ,.). Then all Lisp book
>> authors who are tempted to use '(1 2 3) instead of (list 1 2 3) because
>> it's more concise could use `(1 2 3) and be just as concise
>
> OTOH if the list is used in a functional style (not mutated and not
> compared for identity), its duplication would be a wasted effort.

Yes. And for that you have '(1 2 3). I'm just saying it'd be nice to
have a concise way to build lists that can then be manipulated in
non-functional ways, that doesn't require deep understanding of The
Lisp Way before it can be used safely. Also because backquote isn't
guaranteed to build fresh list structures that means I have to use
COPY-LIST to copy the result of a backquoted expression if I'm going
to muck with it's list structure, say to nconc together a few bits of
code generated by helper functions. In most cases *this* explicit
copying is a waste because the backquote expressions probably *do*
build fresh list structures. But since that's not guaranteed I can't
count on it so I end up doing extra copying.

-Peter
  
-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Marcin 'Qrczak' Kowalczyk
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <pan.2004.08.17.20.27.47.51064@knm.org.pl>
On Mon, 16 Aug 2004 20:59:26 +0000, Peter Seibel wrote:

>>> It's a pity, it seems, that backquote isn't just defined to always
>>> generate new list structure (modulo use of ,.). Then all Lisp book
>>> authors who are tempted to use '(1 2 3) instead of (list 1 2 3) because
>>> it's more concise could use `(1 2 3) and be just as concise
>>
>> OTOH if the list is used in a functional style (not mutated and not
>> compared for identity), its duplication would be a wasted effort.
> 
> Yes. And for that you have '(1 2 3).

But what about
   `(1 2 ,x 3 4)
? Today the "(3 4)" at the tail is usually shared. You would like to
recreate it each time afresh. This consing would be wasted.

In particular if it's a part of a macro, then the list will be indeed
used in a functional style. (Not that efficiency of macros is terribly
important...)

> Also because backquote isn't guaranteed to build fresh list structures
> that means I have to use COPY-LIST to copy the result of a backquoted
> expression if I'm going to muck with it's list structure, say to nconc
> together a few bits of code generated by helper functions. In most cases
> *this* explicit copying is a waste because the backquote expressions
> probably *do* build fresh list structures.

You can use a combination of LIST, CONS and APPEND to archieve minimal
consing.

-- 
   __("<         Marcin Kowalczyk
   \__/       ······@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/
From: Peter Seibel
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <m3oel9xxt1.fsf@javamonkey.com>
Marcin 'Qrczak' Kowalczyk <······@knm.org.pl> writes:

> On Mon, 16 Aug 2004 20:59:26 +0000, Peter Seibel wrote:
>
>>>> It's a pity, it seems, that backquote isn't just defined to always
>>>> generate new list structure (modulo use of ,.). Then all Lisp book
>>>> authors who are tempted to use '(1 2 3) instead of (list 1 2 3) because
>>>> it's more concise could use `(1 2 3) and be just as concise
>>>
>>> OTOH if the list is used in a functional style (not mutated and not
>>> compared for identity), its duplication would be a wasted effort.
>> 
>> Yes. And for that you have '(1 2 3).
>
> But what about
>    `(1 2 ,x 3 4)
> ? Today the "(3 4)" at the tail is usually shared. You would like to
> recreate it each time afresh. This consing would be wasted.
>
> In particular if it's a part of a macro, then the list will be indeed
> used in a functional style. (Not that efficiency of macros is terribly
> important...)

Which is my point. Most of the time when we use a backquote (macros)
the difference between creating a few extra cons cells or not is in
the noise. But if backquote always generated new list structure then
it could be used when we just want to cons up a list that looks a
particular way without worrying about whether it might later be passed
to some destructive operator. Which seems like goodness to me. And
since folks who really *want* to be sure that they are consing
minimally, i.e. that `(1 2 ,x 3 4) uses a literal '(3 4) can't use
backquote today since it's not guaranteed not to cons up all new list
structure.

>> Also because backquote isn't guaranteed to build fresh list
>> structures that means I have to use COPY-LIST to copy the result of
>> a backquoted expression if I'm going to muck with it's list
>> structure, say to nconc together a few bits of code generated by
>> helper functions. In most cases *this* explicit copying is a waste
>> because the backquote expressions probably *do* build fresh list
>> structures.
>
> You can use a combination of LIST, CONS and APPEND to archieve
> minimal consing.

But I don't want minimal consing. I want a reasonable but known amount
of consing. I'd say if you want *minimal* consing then you should have
to do the extra work--write (list* 1 2 x '(3 4)) rather than `(1 2 ,x
3 4), leaving backquote for what I see as the mainline case where a
bit of extra consing doesn't matter when weighed against the advantage
of not having to worry about munging literals.

In other words we are just discussing/disagreening which default
brings more overall goodness to the world. Which is, of course, moot
because nobody is going to open up the language standard for this kind
of nibbling around the edges. ;-)

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: ·········@random-state.net
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <cfjk2j$5t029$1@midnight.cs.hut.fi>
Peter Seibel <·····@javamonkey.com> wrote:

>   The constructed copy of the template might or might not share list
>   structure with the template itself.

> I take that to mean that the outer most level the list produced by the
> backquoted expression is, well, a "constructed copy of the template"
> even if it happens to share structure with subelements of the
> template. Thus this is perfectly well defined:

>   (loop repeat 10 nconcing `(x y))

> while this is undefined:

>   (loop repeat 10 nconcing '(x y))

Both are undefined, I _think_. I don't see how copies would be required
in the absence of any substitutions, since interpreting the first as 
'(x y) would satisfy the "same under EQUAL" criterion.

OTOH, in eg.

 `(a ,b c d)

the only legal sharing would seem to with the tail (C and D). Eg:

 (list* 'a b '(c d))

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."
From: Kalle Olavi Niemitalo
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <87k6w22igf.fsf@Astalo.kon.iki.fi>
·········@random-state.net writes:

> OTOH, in eg.
>
>  `(a ,b c d)
>
> the only legal sharing would seem to with the tail (C and D).

B might be a constant variable.
From: Lars Brinkhoff
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <85r7qans9w.fsf@junk.nocrew.org>
Peter Seibel <·····@javamonkey.com> writes:
> That is, does `(...) always get read as code that conses up a new
> list? 2.4.6 says:
> 
>   The constructed copy of the template might or might not share list
>   structure with the template itself.

But later is says:

  An implementation is free to interpret a backquoted form F1 as any
  form F2 that, when evaluated, will produce a result that is the same
  under equal as the result implied by the above definition [...]

So, by my interpretation, an implementation could cache the result of,
e.g., `(x ,y) and always return the same (eq) object.

My conclusion has been to never ever assume fresh consing from
backquote.

-- 
Lars Brinkhoff,         Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting    http://www.brinkhoff.se/
From: ·········@random-state.net
Subject: Re: Are the lists produced by backquote always non-literal?
Date: 
Message-ID: <cfknru$5o0dg$1@midnight.cs.hut.fi>
Lars Brinkhoff <·········@nocrew.org> wrote:

>   An implementation is free to interpret a backquoted form F1 as any
>   form F2 that, when evaluated, will produce a result that is the same
>   under equal as the result implied by the above definition [...]

> So, by my interpretation, an implementation could cache the result of,
> e.g., `(x ,y) and always return the same (eq) object.

After the bit your quote it goes on to require the side-effects of
subtitution forms take place. 

So `(x ,y) could be cached only if it was proven that Y is side-effect
free, or by always evaluating Y but returning the cached list when the
value of Y permits.

> My conclusion has been to never ever assume fresh consing from
> backquote.

Sounds familiar. ;-) My point was that side-effects in backquote
substitution _can_ be relied on.

Cheers,

 -- Nikodemus                   "Not as clumsy or random as a C++ or Java. 
                             An elegant weapon for a more civilized time."