Subject: Re: bug#40692: 28.0.50; Constant list modified inside function

From: Štěpán Němec <[email-masked]>
Date: Sun, 19 Apr 2020 09:08:37 +0200

On Sun, 19 Apr 2020 00:49:02 +0200
Michael Heerdegen wrote:

> Štěpán Němec <[email-masked]> writes:
>
>> > Now, I understand reference semantics of lists in general, but it
>> > seems like this should be different. If this behavior is intentional,
>>
>> I think it is, although I admit I was confused by it, too, as I've
>> somehow come to believe that e.g. `(list) macroexpands to (list 'list),
>> but that's not the case: it expands to '(list).
>
> Yes, I had been bitten by this as well some time ago.  I don't find the
> discussion anymore, I had asked somewhere and the answer was that it's
> an intended feature of backquote to produce an expansion like that.

The "optimization" in absence of unquoted terms seems reasonable, and
e.g. SBCL behaves the same.

I find http://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm
somewhat ambiguous, but http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html
is quite clear:

"Semantics: If no unquote or unquote-splicing forms appear within the <qq
template>, the result of evaluating (quasiquote <qq template>) is
equivalent to the result of evaluating (quote <qq template>)."

Also:

"A quasiquote expression may return either fresh, mutable objects or
literal structure for any structure that is constructed at run time
during the evaluation of the expression. Portions that do not need to be
rebuilt are always literal."

-- 
Štěpán