ChezScheme icon indicating copy to clipboard operation
ChezScheme copied to clipboard

underscore in auxiliary literals of syntax-rules

Open fedeinthemix opened this issue 9 years ago • 5 comments

I'm trying to use the popular matcher by Alex Shinn https://github.com/LemonBoy/matchable-egg/blob/master/match.scm

I'm facing the problem that the above match syntax uses an underscore (_) as an auxiliary literal in a syntax-rules form. I know that R6RS explicitly forbids this in Sec. 11.19. However, in R7RS peoples changed their mind and there it is allowed (Sec. 4.3.2).

I'm wondering if there is any workaround in Chez Scheme to allow its use (apart from using another, non-"standard" symbol), or if there is any plan for that.

Thanks!

fedeinthemix avatar May 19 '16 13:05 fedeinthemix

I wouldn't mind changing this if we introduce it for the non-r6rs version of syntax-rules. If you expect to use the r6rs version of syntax-rules with that srfi, that won't help.

You can always kill the special meaning of underscore by rebinding it, e.g.:

> (let ((_ 0))
    (define-syntax a
      (syntax-rules (_)
        [(_ _) 'yes]
        [(_ x) 'no]))
    (list (a _) (a 4)))
(yes no)

The same binding for underscore needs to be visible both at the definition site and at the use sites.

dybvig avatar May 19 '16 16:05 dybvig

I would welcome changing this for the non-r6rs version.

Thanks for your reply!

fedeinthemix avatar May 19 '16 18:05 fedeinthemix

I've found a similar problem with another auxiliary identifier used in the same match syntax: '..1'. In R6RS mode I get the error:

Exception in read: ..1 symbol syntax is not allowed in #!r6rs mode at line ...

In non-R6RS mode it works without problems. Is this also something mandated by the R6RS standard (I couldn't find)? If not, it would be nice to support it.

fedeinthemix avatar May 21 '16 15:05 fedeinthemix

The production for <identifier> in r6rs section 4.2.1 does not admit sequences of characters starting with a period except for the "peculiar identifier" ....

jltaylor-us avatar May 21 '16 21:05 jltaylor-us

Indeed. Thanks for pointing me to the right place!

fedeinthemix avatar May 21 '16 22:05 fedeinthemix