ChezScheme icon indicating copy to clipboard operation
ChezScheme copied to clipboard

Running `,@ in the REPL does not throw an exception.

Open NoahStoryM opened this issue 2 years ago • 1 comments

What program did you run?

Chez Scheme Version 9.5.7
Copyright 1984-2021 Cisco Systems, Inc.

> `,@0
,@0
> `,@v
,@v
> 

What should have happened?

I read the introduction about ,@ in r6rs, I think `,@ must be illegal usage:

If an (unquote-splicing expression . . . ) form appears inside a qq template, then the expressions must evaluate to lists; the opening and closing parentheses of the lists are then “stripped away” and the elements of the lists are inserted in place of the unquote-splicing form.

NoahStoryM avatar Mar 19 '22 09:03 NoahStoryM

This is an interesting issue. I think the r6rs specification has some edge cases where the descriptive text doesn't quite do what you'd expect in conjunction with the grammar for quasiquote expressions given at the end of the section. Let's take one of these specific examples and walk it through the grammar.

Starting with the reader expansion of the first example: (quasiquote (unquote-splicing 0)) This enters the grammar with (quasiquote <qq template>), and we follow the productions:

  • <qq template> → <qq template 1> (binding (unquote-splicing 0))
  • → <list qq template 1>
  • ( <qq template or slice 1>* ) (binding the two list items unquote-splicing and 0)
  • → <qq template 1> → <lexeme datum> for both items

This never reaches the <splicing unquotation> production in the grammar.

A separate issue is that Chez Scheme does not validate that the <expression>(s) inside an unquote-splicing evaluate to lists. The spec says they must, but it doesn't say whether the implementation should verify that (or suggest any behavior if they are not). Sometimes the program succeeds, and sometimes it fails:

> `(,@0)
0
> `(0 ,@0)
(0 . 0)
> `(0 ,@0 1)
Exception in append: 0 is not a proper list
Type (debug) to enter the debugger.

In my opinion, the current behavior is consistent with the letter (if perhaps not the spirit) of the spec, and most importantly is consistent with any quasiquotation forms that are correct under more restrictive interpretations of the spec. In any case, I think it unlikely that the current behavior of the Chez Scheme quasiquote will change.

jltaylor-us avatar Mar 21 '22 01:03 jltaylor-us