Racket认为宏应用就是函数应用

问题描述 投票:0回答:0

我正在做一个球拍项目,作为其中的一部分,我想将某些算术运算编码为整数。为了避免重复我自己,我尝试制作了几个在

match
语句中自动生成解码臂的宏。

这里是二进制数值运算的宏:

(define-syntax-rule (decode-bin-num-op (op val))
  (with-getters ([floating-point? 60 60]
                 [target 59 57]
                 [in0 56 54]
                 [in1 53 51])
    (op (floating-point? val) (target val) (in0 val) (in1 val))))

(define-syntax decode-bin-num-ops
  (syntax-rules ()
    [(_ val ((op id) ...))
     (begin (id (decode-bin-num-op (op val))) ...) ]))

但是,当我尝试如下使用宏时:

(decode-bin-num-ops instruction ([ADD #b1000]
                                     [SUB #b1001]
                                     [MUL #b1010]
                                     [DIV #b1011]))

我收到以下错误:

Type Checker: could not apply function;
 wrong number of arguments provided
  expected: 4
  given: 1 in: (ADD 8)

似乎认为

(ADD 8)
(等等)是函数应用程序,而不是宏的一部分。

发生这种情况有什么原因吗?

macros lisp racket
© www.soinside.com 2019 - 2024. All rights reserved.