【发布时间】:2016-04-26 16:14:22
【问题描述】:
我希望能够写作:
(nota E2 82)
代替:
(define E2
(network ()
[sunet <= sine-wave 82]
[out = (+ sunet)]))
我知道我可以使用宏来做到这一点并尝试写这个:
(define-syntax (nota stx)
(syntax-case stx ()
[(nota x) #'(network ()
[sunet <= sine-wave x]
[out = (+ sunet)])]))
但我收到此错误:
nota: bad syntax in: (nota E2 82)
【问题讨论】:
-
你忘记
define了吗? -
你得到“错误语法”错误的原因是因为
(nota x)表明你的宏只接受一个“参数”,但你给了它两个。正如@stchang 所提到的,您似乎想要添加一个额外的参数并将define包含在您的扩展中。
标签: macros pattern-matching racket define-syntax