I'd like to create a syntactic form in Racket that can accept a keyword argument, the way some functions can.
Having reduced it to a simple example, I tried writing:
(define-syntax sum-of-products
(syntax-rules (#:extra)
[(sum-of-products ([a b] ...))
(+ (* a b) ...)]
[(sum-of-products ([a b] ...) #:extra extra)
(+ extra (* a b) ...)]))
Such that the following would then work:
(sum-of-products ([2 2] [3 3])) → 13
(sum-of-products ([2 2] [3 3]) #:extra 5) → 18
Unfortunately, Racket calls this "bad syntax", so obviously that attempt wasn't correct.
Can this be done?