On Thu, 27 Mar 2003, Hoehle, Joerg-Cyril wrote:
> Date: Thu, 27 Mar 2003 11:13:40 +0100
> From: "Hoehle, Joerg-Cyril" <Joerg-Cyril.Hoehle@...>
> To: clisp-list@...
> Cc: kaz@...
> Subject: Re: New, from-scratch implementation of backquote.
> here are some more testcases:
> `(a (,@3) b)
> (A 3 B)
This works, because (APPEND ... 3) works. Also:
`(a (2 ,@3) b)
(A (2 . 3) B)
I consider these behaviors extensions, because the HyperSpec states that
`(x1 .. xn) is handled like `(x1 ... xn . nil) using the `(... . atom)
So the abstract semantics say that you should get:
(APPEND 3 'NIL) -> ERROR
But I deviate from the abstract semantics in my implementation and
do not handle (x1 ... xn . nil) in the same way as any other atom;
I chop the NIL off so (APPEND 3) is generated (and then optimized).
> I mention this one because I learnt about the (,@x) trick only
> recently (from cll?), despite having used CL for over a decade.
This tells me that the trick is circulating in the culture, which tells
me that other Lisp implemenations have it, so it would indeed be a bad
idea to reject the syntax. Oh, and among those ``other''
implementations is the unpatched CLISP.
> I still find this (degenerate?) case a little weird, it does not fit
> my mental model: ,@ -> produce a proper list, whereas here the outer
> parentheses disappear, depending on the inner value. But this property
> can have its uses.
That's right; it does not fit the mental model of list splicing at all.
Nor does it fit the mental model ``if it's an atom, splice it in
alone as if it were a list of one element'', because then it would
work in any position, not just the last.
It only fits that mental model which pictures it as supplying an
argument to append: `(,@A ,@B ,@C) --> (APPEND A B C). So if C
evaluates to an atom, you get (APPEND A B <atom>), which is supported
by that function.
> BTW, how's ., support going? I use that quite often. (Actually, it's
> not backquote special, it's dotted list syntax + ,).
> `(a b .,c) -> (list* 'a 'b c)
Supported from day one; I was working closely from the CLHS, so as to
not miss any requirements.
(macroexpand-1 '`(a b . ,c)) -> (LIST* 'A 'B C)
> `(a ,@b .,c) ->? (append '(a) b c) -> (a <^b...> <^c...>)
> `(a ,. ...
(macroexpand-1 '`(a ,@b . ,c)) -> (CONS 'A (APPEND B C))