What are some Syntax Class idioms that you enjoy?

Hi, Racket Discourse.

What kinds of idioms do you enjoy using when writing syntax classes for syntax-parse and friends?

I stumbled on this nice little turn of phrase for a choice from a group of options:

(pattern (@ (~or β:bag-expr
                 α:atom-expr
                 ρ:raise-expr
                 μ:merge-expr)
            (~optional ?expt:expt-expr))
  ; al die eendjies stap in 'n ry
  #:with bag? #'(~? β.here
                (~? μ.here
                (~? ρ.bag? #false)))
  #:with base #'(~? β.wrap
                (~? μ.wrap
                (~? ρ.base α.self)))
  #:with expt #'(* (~? ρ.expt) (~? ?expt.term 1)))

I don't know if this is achieved more easily by some other form, but it has a charm to it.

1 Like