是否可以将切片语法封装成语法-class?

Is it possiable to encapsulate a splicing syntax into syntax-class?

例如下面的程序

(begin-for-syntax
  (define-splicing-syntax-class bindings
    (pattern (b*:bind ...)))

  (define-syntax-class bind
    #:datum-literals (:)
    (pattern (name:id : ty))))

(define-syntax-parser def
  [(_ name:id b*:bind ...)
   #''ok])

(def a [a : Num] [b : Num])

(define-syntax-parser def2
  [(_ name:id b*:bindings)
   #''ok])

(def2 a [a : Num] [b : Num])

def 按预期工作,但 def2 必须更改为:

(def2 a ([a : Num] [b : Num]))

我想使用 bindings 但仍然得到 def 形式

你需要在bindings的定义中使用~seq:

(define-splicing-syntax-class bindings
    (pattern (~seq b*:bind ...)))