Here's one way:

  (~and z:id
       (~fail #:unless (free-identifier=? #'z #'zeta)
              "expected the identifier `zeta`"))

Another way is to make a syntax class (either specifically for `zeta` or parameterized by the identifier) that does the same check.

Ryan


On 4/3/18 8:33 AM, Matthew Butterick wrote:
Consider the difference in results below. How would I persuade `syntax-parse` 
to match literal identifiers in the `free-identifier=?` sense that 
`syntax-case` does? (and thereby allow unbound identifiers to be compared also)

IIUC, `#:literals` is too strict, as it insists that every listed identifier 
have a binding; `#:datum-literals` is too lenient, as it does not compare 
bindings at all, but rather just the symbol.

;;;;;;;;;;;;;;;;;;;;;;;;;

#lang racket
(require math rackunit)

(module mod racket
  (require (for-syntax syntax/parse))
  (define-syntax (mac stx)
    (syntax-parse stx
      #:literals () ;; <- can't put `zeta` here, produces an error
      #:datum-literals (zeta)
      [(_ zeta) #''match]
      [else #''nope]))
  (provide mac))
(require 'mod)

(check-equal? (mac zeta) 'match)


(module mod2 racket
  (require (for-syntax syntax/parse))
  (define-syntax (mac2 stx)
    (syntax-case stx (zeta)
      [(_ zeta) #''match]
      [else #''nope]))
  (provide mac2))
(require 'mod2)

(check-equal? (mac2 zeta) 'nope)


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to