[racket] define-syntax-class

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Wed Apr 27 22:26:27 EDT 2011

What am I missing in the code below (reproduced from the "Fortifying
Macros" paper)? When run, this gives me an error: "syntax-parse: not
defined as syntax class in: binding". If I move the syntax class
definition into the bodies of define-syntax, then it works, but that
defeats the purpose of being able to define a reusable syntax class...

#lang racket/base

(require syntax/parse
         (for-syntax syntax/parse

(define-syntax-class binding
  #:description "binding pair"
  (pattern [var:identifier rhs:expr]))

(define-syntax (let stx)
  (syntax-parse stx
     [(let (b:binding ...) body:expr)
      #:fail-when (check-duplicate-identifier (syntax->list #'(b.var ...)))
            "duplicate variable name"
      #'((λ (b.var ...) body) b.rhs ...)]))

(define-syntax (let1 stx)
  (syntax-parse stx
     [(let1 b:binding body:expr)
      #'((λ (b.var) body) b.rhs)]))

Thanks in advance,

--- nadeem

Posted on the users mailing list.