(Sorry for broken threading, I'm replying to a post from the mailing
list archive)
Peter Bex wrote:
> >
> > I think the issue is a little more complex that this, it has to do with the
> > fact that nested unquote-splicing was accidentally broken in Scheme, but since I
> > don't remember the details offhand, let me quote Al* Petrofsky on this issue.
>
> Thank you for this rationale. I asked about the same issue before, but
> that part of my message was ignored. I considered the R6RS change rather
> unintuitive, but the case of unquoting to undo nested quoting levels for
> one spliced unquote makes sense.
Just trying to bring all information together.
This is how an implementation of R5RS should behave (assuming it
doesn't extend the semantics of quasiquote):
> `,@(list 1 2) => error (trying to "splice" into a scalar operand of the 'quasiquote' form)
> ``,,@(list 1 2) => error (trying to "splice" into a scalar operand of the 'unquote' form)
> ``,@,@(list 1 2) => error (trying to "splice" into a scalar operand of the 'unquote-splicing' form)
In all these cases 'unquote-splicing' is trying to "splice" its
contents into a form (quasiquote, unquote or another
unquote-splicing), which accepts only a single element. That could
potentially work if the list in 'unquote-splicing' had exactly one
element in it, but that's a corner case few people care about.
If 'unquote' and 'unquote-splicing' were both taking any number of
operands (like in R6RS), the result could look like this:
> `,@(list 1 2) => error (trying to "splice" into a scalar operand of the 'quasiquote' form)
> `,@(list 1) => 1 (optional special case for lists of length 1)
> `(unquote 1) => 1
> `(unquote) => error (0 operands in 'quasiquote' form)
> `(unquote 1 2) => error (trying to insert multiple values into the 'quasiquote' form)
> ``,,@(list) => `(unquote)
> ``,,@(list 1) => `,1
> ``,,@(list 1 2) => `(unquote 1 2)
> ``,@,@(list) => `(unquote-splicing)
> ``,@,@(list 1) => `,@1
> ``,@,@(list 1 2) => `(unquote-splicing 1 2)
The question is whether we want to do it at all. Note that e.g.
``,,@(list) and ``,@,@(list) both expand into forms that are illegal
when expanded again. Perhaps that's not a big issue but is not a
particularly elegant design.
This could be fixed if 'quasiquote' itself (and for consistency also
'quote') were also taking any number of operands and "splice" them
into a user's form invoking it.
In such case above examples would expand to:
> `,@(list 1 2) => 1 2 (two values inserted in the calling form or the interactive session)
> `,@(list 1) => 1
> `(unquote 1) => 1
> `(unquote) => nil (no value)
> `(unquote 1 2) => 1 2
> ``,,@(list) => `(unquote)
> ``,,@(list 1) => `,1
> ``,,@(list 1 2) => `(unquote 1 2)
> ``,@,@(list) => `(unquote-splicing)
> ``,@,@(list 1) => `,@1
> ``,@,@(list 1 2) => `(unquote-splicing 1 2)
and for consistency:
> (quote 1 2) => 1 2 (two values inserted in the calling form or the interactive session)
> (quote) => nil (no value)
Andrzej
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports