What kind of `with`s have you come up with?

I made a version of the Common Lisp with-slots macro for Racket structs recently that I'm proud of.

(require soup-lib/struct)
(struct demo (a b c) #:transparent #:mutable)
(define x (demo 1 2 3))
(with-slots demo (a b) x
  (set! b (+ a b))
  (print x)) ; (demo 1 3 3)

Vital to the implementation are make-variable-like-transformer and the struct-id syntax class.

2 Likes