3 ms·
I sent a bug report to the clisp-list mailing list just days ago, but it didn't come through. Date: Mon, 04 May 2015 07:20:34 -0700 To: Clisp list <clisp-l
by kazinator 12y ago
I sent a bug report to the clisp-list mailing list just days ago, but it didn't come through.
Date: Mon, 04 May 2015 07:20:34 -0700
To: Clisp list <clisp-list@lists.sourceforge.net>
Subject: Invalid backquote reduction: ,',@x
Hi all,
I've discovered that (admittedly, an old version) of CLISP is
reducing a certain backquote syntax according to a hare-brained
user expectation instead of diagnosing en error.
Pardon me if this has been fixed more recently.
In a double backquote, if you quote a splice, and then unquote
the quote, the unquote and quote cancel out naively.
(Is that, by chance, my doing???)
CLISP:
[1]> (let ((a '(1 2 3))) ``(a b c ,',@a))
'(A B C 1 2 3)
Of course the above quote form then eval-s to (A B C 1 2 3).
Clozure CL:
? (let ((a '(1 2 3))) ``(a b c ,',@a))
(LIST* 'A (LIST* 'B (LIST* 'C (LIST (QUOTE 1 2 3)))))
? (eval *)
> Error: Too many arguments in form (QUOTE 1 2 3) .
The Clozure output (IMO correct) illustrates precisely what
wrong, so I almost don't have to say anything more.
The construct ',@a is (QUOTE ,@A) which stuffs zero or more
things into the QUOTE syntax where there should be exactly
one, potentially resulting in an incorrect quote syntax.
So given (UNQUOTE (QUOTE (SPLICE A))), then only if A
generates exactly one item, are we justified in
"canceling" the QUOTE and UNQUOTE! In other cases,
it is invalid and should be diagnosed as an abuse of
QUOTE.
* * *
Is there a possibility that this could be documented
as an extension? I think it's too much of a special case
in its present form, because it only works when the
QUOTE form is an immediate argument of the UNQUOTE,
as seen from this CLISP output:
[2]> (let ((a '(1 2 3))) ``(a b c ,(list ',@a)))
(LIST 'A 'B 'C (LIST (QUOTE 1 2 3)))
We might imagine that a possibly meaningful
extension (which swiftly reveals itself to be otherwise)
along these lines:
"If a splice is the child, direct or indirect,
of an unquote, then the unquote *and all
intervening syntax* distributes over the splice,
as if by replication over the elements. That
is to say ,(syntax ,@form) is treated as if
it were ,(syntax ,(first form)) ,(syntax ,(second form))
and so on, where form is evaluated only once,
and the number of unquotes depends on the size of
the output of form.
According to the above rule, we would then expect:
[2]> (let ((a '(1 2 3))) ``(a b c ,(list ',@a)))
;; FANTASY:
(LIST 'A 'B 'C (LIST (QUOTE 1)) (LIST (QUOTE 2)) (LIST (QUOTE 3)))
The problem is that this interferes with existing semantics;
the structure ,(syntax ,@form) already has firm meaning,
which is that form is evaluated to create arguments which
are substituted into SYNTAX, and then this is unquoted, leading
to the evaluation a single instance of SYNTAX as an operator.
When SYNTAX is QUOTE, no special exception can be made;
,(quote ,@form) must also mean "zero or more arguments
into quote which is then evaled in the next round, possibly
leading to a quoting error".