I would like to create a syntax form in Racket that can take a keyword argument, as some functions can.
Reducing it to a simple example, I tried to write:
(define-syntax sum-of-products (syntax-rules (#:extra) [(sum-of-products ([ab] ...)) (+ (* ab) ...)] [(sum-of-products ([ab] ...) #:extra extra) (+ extra (* ab) ...)]))
So then the following will 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 it is obvious that the attempt was incorrect.
Can this be done?
macros scheme racket
Taymon
source share