From: Sebastian Stern
Subject: Unquote
Date: 
Message-ID: <429f6a01$0$91142$dbd45001@news.wanadoo.nl>
"Comma is invalid if used other than inside the body of a backquote
expression as described above." [Common Lisp HyperSpec, 2.4.7, Comma]

Why is this?

When I was learning backquote/quasiquote, I had just accepted this as the
way things work, but after investigating some articles on the interpretation
of S4 modal logic in terms of programming languages, I am not so sure.

Should it not be possible (and better, in the sense that it eliminates the
above restriction) to have an UNQUOTE special operator?  (The comma would
then just be its abbreviating macro character).  The operation of the
UNQUOTE special operator would be the same of that of the oridinary UNQUOTE,
except that it would also be allowed that an UNQUOTE appears outside a
corresponding backquote/quasiquote.  Why does CL have the requirement that
an unquote may only appear in a backquote?

(Scheme does not have this restriction as far as I can tell (see R5RS,
5.2.6, Quasiquotation).  But some Scheme implementations signal an error,
while others do not.  Why does R5RS lack the requirement that unquote may
only appear in a quasiquote?)

--
Sebastian Stern

Freedom is the freedom to say (= (+ 2 2) 4).  If that is granted, all else
follows.

From: Jens Axel Søgaard
Subject: Re: Unquote
Date: 
Message-ID: <429f7003$0$210$edfadb0f@dread12.news.tele.dk>
Sebastian Stern wrote:
> (Scheme does not have this restriction as far as I can tell (see R5RS,
> 5.2.6, Quasiquotation).  But some Scheme implementations signal an error,
> while others do not.  Why does R5RS lack the requirement that unquote may
> only appear in a quasiquote?)

   4.2.6 Quasiquotation has this paragraph

   The two notations `<qq template> and (quasiquote <qq template>) are identical
   in all respects. ,<expression> is identical to (unquote <expression>), and
   ,@<expression> is identical to (unquote-splicing <expression>).

This means that it is possible to hi-jack , (comma) for other purposes.

   > (let ((unquote -))
       ,42)
   -42

In constrast

   > ,42
   unquote: not in quasiquote in: (unquote 42)

(an "reference to undefined indentifier: unquote" would
  be a perfectly correct error message, but the above is
  more helpful)

Other Schemes use a top-level unquote for repl commands
(see <http://s48.org/1.2/manual/s48manual_13.html>). The cle
clever thing is that 1) it is that to type comma-commands,
and 2) the reader doesn't need rewriting.

-- 
Jens Axel Søgaard
From: Sebastian Stern
Subject: Re: Unquote
Date: 
Message-ID: <429f80bb$0$40852$dbd4d001@news.wanadoo.nl>
Jens Axel S�gaard:
| clever thing is that 1) it is that to type comma-commands,
| and 2) the reader doesn't need rewriting.

Sorry, I cannot parse this sentence.  And is there a deep idea behind using
UNQUOTE for REPL commands, or is that just an arbitrary design decision to
prevent RSI?

--
Sebastian Stern

Freedom is the freedom to say (= (+ 2 2) 4).  If that is granted, all else
follows.
From: Jens Axel Søgaard
Subject: Re: Unquote
Date: 
Message-ID: <429f8866$0$274$edfadb0f@dread12.news.tele.dk>
Sebastian Stern wrote:
> Jens Axel Søgaard:
> | clever thing is that 1) it is that to type comma-commands,
> | and 2) the reader doesn't need rewriting.
> 
> Sorry, I cannot parse this sentence. 

The clever thing is 1) that it is easy to type comma-commands,
and 2) that no changes to the reader is neccesarry.

> And is there a deep idea behind using
> UNQUOTE for REPL commands, or is that just an arbitrary design decision to
> prevent RSI?

No - that is just a convenient (for the implementor) hack.

-- 
Jens Axel Søgaard
From: Rob Warnock
Subject: Re: Unquote
Date: 
Message-ID: <7oSdnTfHGqi6ijjfRVn-iw@speakeasy.net>
Sebastian Stern <··············@wanadoo.nl> wrote:
+---------------
| "Comma is invalid if used other than inside the body of a backquote
| expression as described above." [Common Lisp HyperSpec, 2.4.7, Comma]
| Why is this?
...
| Should it not be possible (and better, in the sense that it eliminates the
| above restriction) to have an UNQUOTE special operator?  (The comma would
| then just be its abbreviating macro character). The operation of the
| UNQUOTE special operator would be the same of that of the oridinary
| UNQUOTE, except that it would also be allowed that an UNQUOTE appears
| outside a corresponding backquote/quasiquote.
+---------------

Personally, I agree that it would be "better" in a certain sense, in
that it would permit user macros to use what Scheme calls QUASIQUOTE,
UNQUOTE, and UNQUOTE-SPLICING (backquote, command, and comma-at, resp.)
for doing their own template re-writing [and the CLHS certainly *permits*
this, see Section 2.4.6.1 "Notes about Backquote", but does not require it].
A great example of this is the Scheme Shell <http://www.scsh.net/>, which
allows one to write things like this:

    (let ((foo "filename"))	; RUN is a Scsh macro that does what
      (run (ls -l ,foo)))	;  might be called "implicit quasiquoting".

    (run (cc ,file ,@flags))	; Compile FILE with FLAGS.

Unfortunately those are illegal to a standard CL reader, as you have noted,
so in a (hypothetical) "CLsh" the above would have to look like this:

    (let ((foo "filename"))
      (run `(ls -l ,foo)))	; Note explicit backquote

    (run `(cc ,file ,@flags))	; (ditto)

+---------------
| Why does CL have the requirement that an unquote may only appear
| in a backquote?
+---------------

When this topic came up before, most of the old dogs said it was because
there were so many different existing implementations of quasiquotation
out there already -- some doing it all in the reader, some rewriting
into idiosyncratic special forms, some doing a mixture of the two,
and some even doing pretty agressive optimization of how the resulting
s-expr got constructed at runtime (or even compile time!) -- that the
best the CL committee could come up with was the set of "as if" rules
that you now see in CLHS 2.4.6 "Backquote":

    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, provided
    that the side-effect behavior of the substitute form F2 is also
    consistent with the description given above.

Note the various possible legal renderings of this:

    `((,a b) ,c ,@d)

which are given following the above quote. It would be very difficult
(if not impossible) for a "CLsh" to figure out in any portable way
[and in some cases, even within a single implemetation] just what
the user had originally typed. That is, given this "CLsh" call:

    (run `((,a b) ,c ,@d))

the argument to the RUN macro might be any of the forms listed.

Remember, it is the *reader* doing the rewriting in CL, so the
RUN macro never sees the original form at all.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607