
Awesome, thanks!

Consider the following macro: (define-syntax-rule (adds-new-bindings x)
(begin
(define x 3)))
If I do: (adds-new-bindings foo)
This appears to set foo
to 3, as I’d expect. However, suppose I want adds-new-bindings
to introduce another binding x-baz
with a value 4, where x-baz
comes from adding -baz
to the identifier passed in. In other words, I’d get the following behavior: (adds-new-bindings foo)
foo ;; 3
foo-baz ;; 4
How could I go about accomplishing this?

(require syntax/parse/define
(for-syntax racket/syntax))
(define-syntax-parse-rule (adds-new-bindings x)
#:with new-id (format-id #'x "~a-baz" #'x)
(begin
(define x 3)
(define new-id 4)))
(adds-new-bindings foo)
foo ;=> 3
foo-baz ;=> 4

Perfect, thank you so much!

I would probably have written (define-syntax-parse-rule (adds-new-bindings x:id) …)
but this is essentially what I was going to suggest.

Also, use (format-id #'x "~a-baz" #'x #:subs? #true)
to get identifier renaming and binding arrows to work correctly.

Thank you for the advice, this is great