Subject: [clisp-list] Re: New, from-scratch implementation of backquote.

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Mar 27 02:17:28 2003

Kaz,

here are some more testcases:

`(a (,@3) b)
(A 3 B)

`(a (,@3 4) b)
ERROR

I mention this one because I learnt about the (,@x) trick only recently (from cll?), despite having used CL for over a decade.
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.

There's always something new to learn in CLtL2/ANSI-CL :)

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)
`(a ,@b .,c) ->? (append '(a) b c) -> (a <^b...> <^c...>)
`(a ,. ...

Hmm, above (,@X) behaviour looks suspicious considering
http://www.lispworks.com/reference/HyperSpec/Body/02_df.htm
* `(x1 x2 x3 ... xn . atom) may be interpreted to mean
     (append [ x1] [ x2] [ x3] ... [ xn] (quote atom))
    -- [,@form] is interpreted as form.
and the requirement that append shall accept only proper lists (except for the last).
Neither does it seem to be covered by a CLtL2 interpretation of backquote and append
http://www.supelec.fr/docs/cltl/clm/node190.html#BACKQUOTE
http://www.supelec.fr/docs/cltl/clm/node149.html

Regards,
	Jorg.

---

From: Kaz Kylheku <[email-masked]>
Date: Thu Mar 27 07:26:03 2003

On Thu, 27 Mar 2003, Hoehle, Joerg-Cyril wrote:

> Date: Thu, 27 Mar 2003 11:13:40 +0100
> From: "Hoehle, Joerg-Cyril" <[email-masked]>
> To: [email-masked]
> Cc: [email-masked]
> Subject: Re: New, from-scratch implementation of backquote.
> 
> Kaz,
> 

This works, because (APPEND ... 3) works. Also:

  `(a (2 ,@3) b)

gets you

  (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)
case.

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 + ,).

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...>)

(macroexpand-1 '`(a ,@b . ,c)) -> (CONS 'A (APPEND B C))