(球拍) 具有从模块导入的标识符的"Cannot reference an identifier before its definition"



我有一个文件"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已经生成了一个模块。

相关内容

最新更新