我有一个文件"exceptions.rkt"
#lang racket
(module exceptions racket
(provide Macro/Raise Macro/Assert Macro/Assert* Macro/Domain-Assert)
; ... Definitions for provided symbols...
) ; End of module, end of file
Macro/Raise
等实际上并不是用定义语法定义的宏,它们只是用syntax-rules
生成并分配名称的一元函数
(define Macro/Raise
(syntax-rules ()
; ... body not important ...
))
在与"exceptions.rkt"相同的文件夹中,我有一个文件"tables.rkt"。
#lang racket
(module tables racket
(require "exceptions.rkt")
(define-syntax Assert Macro/Assert)
; ... more stuff...
) ; End of module, end of file
但这会导致Macro/Assert: undefined; cannot reference an identifier before its definition in module: 'tables phase: 1
我试过阅读文档,但无法弄清楚我做错了什么......那我做错了什么呢?
为了使定义在宏定义阶段可用,请使用for-syntax
:
(require (for-syntax "exceptions.rkt"))
您不需要代码上的(module exceptions racket ...)
包装器,因为#lang racket
已经生成了一个模块。