Racket: syntax-parse binding arrow points to the wrong binding occurrence

Created on 4 Nov 2017  路  4Comments  路  Source: racket/racket

In the following code, the binding arrow of #'e at B points to the e at A.

#lang racket/base

(require syntax/parse)

(syntax-parser
  [e #'e]  ; A
  [e #'e]  ; B
  )

stxparse

Most helpful comment

I'm not sure what argument you have in mind, but the fact that this one does the more obvious thing seems like a counterargument:

(syntax-parser
  [e #'e]
  [f #'f])

All 4 comments

Arguably, this is correct.

I'm not sure what argument you have in mind, but the fact that this one does the more obvious thing seems like a counterargument:

(syntax-parser
  [e #'e]
  [f #'f])

Also, I'll note that if I rename "f" to "e" (in my example) and then back I get different program, which also seems like a counterargument.

I think I can see that if there is a common prefix, it's better that the implementation do not re-match the prefix and use the same bound variable. But I would be against exposing this to the user because:

  • Intuitively, the scope of first pattern variable e should span only in the first clause.
  • Renaming does not work anymore. For example, I cannot rename thn and els correctly:
#lang racket/base

(require (for-syntax racket/base)
         syntax/parse)

(define-syntax (reversed-if _)
  (error 'reversed-if "bad syntax"))

(syntax-parser #:literals (quote reversed-if)
 [(reversed-if thn:expr els:expr '#t)
  #'thn]
 [(reversed-if thn:expr els:expr '#f)
  #'els]
 [(reversed-if thn:expr els:expr con:expr)
  #'(if con thn els)])
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sorawee picture sorawee  路  7Comments

billop picture billop  路  5Comments

willghatch picture willghatch  路  7Comments

corpix picture corpix  路  7Comments

willghatch picture willghatch  路  7Comments