mighty-gerbils / gerbil

Gerbil Scheme
https://cons.io
GNU Lesser General Public License v2.1
1.15k stars 110 forks source link

R7RS does not support renaming the ellipsis in syntax-rules #412

Open ar-nelson opened 4 years ago

ar-nelson commented 4 years ago

R7RS syntax-rules supports a form that renames the ellipsis from ... to a different symbol. This syntax is described in section 4.3.2 of r7rs.pdf. For example, this script rename-ellipsis.scm defines a macro where $ is used as the ellipsis:

(import (scheme base)
        (scheme write))

(define-syntax my-list
  (syntax-rules $ ()
    ((my-list xs $)
       (list xs $))))

(display (my-list 1 2 3 4))
(newline)

This script works in other R7RS Schemes (Gauche and Chibi), but fails in Gerbil:

$ gosh -r7 rename-ellipsis.scm
(1 2 3 4)
$ chibi-scheme rename-ellipsis.scm
(1 2 3 4)
$ gxi --lang r7rs rename-ellipsis.scm
*** ERROR IN gx#core-apply-expander__% -- Syntax Error
*** ERROR IN "rename-ellipsis.scm"@5.3
--- Syntax Error: Bad syntax
... form:   (syntax-rules $ () ((my-list xs $) (list xs $)))
vyzo commented 4 years ago

I hadn't realized this made it to the standard; it should be easy to fix however.

vyzo commented 4 years ago

Actually not so easy to fix, it would have to be baked in the syntax-case implementation because it uses ellipsis? to test for that.