我正在使用 GNU Make 中的 guile 支持,我偶然发现了这个奇怪之处:define-syntax
我在“my-gmk.scm”文件中定义和使用的宏按预期工作:
(define-syntax my/gmk-format ; shorthand for `(gmk-expand (format #f ...))`
(syntax-rules ()
[(_ stuff ...)
(let ()
(gmk-expand (format #f stuff ...)) ) ] ))
(display (my/gmk-format "FOO: ~a\n" 'bar))
但是,如果我(load)
将 scm 文件放在另一个 scm 文件中,并尝试以相同的方式使用相同的宏:
(load "my-gmk.scm")
(display (my/gmk-format "BAZ: ~a\n" 'qux))
它失败并显示以下错误消息:
$ make
FOO: bar
Backtrace:
In ice-9/boot-9.scm:
160: 9 [catch #t #<catch-closure 55a1687b3000> ...]
In unknown file:
?: 8 [apply-smob/1 #<catch-closure 55a1687b3000>]
?: 7 [call-with-input-string "(load \"my.scm\")" ...]
In ice-9/boot-9.scm:
2404: 6 [save-module-excursion #<procedure 55a1687bcea0 at ice-9/eval-string.scm:65:9 ()>]
In ice-9/eval-string.scm:
44: 5 [read-and-eval #<input: string 55a1683464e0> #:lang ...]
37: 4 [lp (load "my.scm")]
In ice-9/boot-9.scm:
2404: 3 [save-module-excursion #<procedure 55a1687ae540 at ice-9/boot-9.scm:4051:3 ()>]
4058: 2 [#<procedure 55a1687ae540 at ice-9/boot-9.scm:4051:3 ()>]
In /home/beguiler/src/wtf/my.scm:
4: 1 [#<procedure 55a1687b91e0 ()>]
In unknown file:
?: 0 [#<syntax-transformer my/gmk-format> "BAZ: ~a\n" qux]
ERROR: In procedure #<syntax-transformer my/gmk-format>:
ERROR: Wrong type to apply: #<syntax-transformer my/gmk-format>
make: *** No targets. Stop.
我想了解为什么会发生这种情况。
我的 GNUmakefile 很简单
$(guile (load "my.scm"))