Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Racket) "Cannot reference an identifier before its definition" with identifier imported from module

Tags:

module

racket

I have a file "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 etc are not actually macros defined with define-syntax, they're just unary functions generated with syntax-rules and assigned a name

(define Macro/Raise
  (syntax-rules ()
; ... body not important ...
))

and in the same folder as "exceptions.rkt", I have a file "tables.rkt".

#lang racket
(module tables racket
    (require "exceptions.rkt")
    (define-syntax Assert Macro/Assert)

; ... more stuff...

) ; End of module, end of file

but this results in Macro/Assert: undefined; cannot reference an identifier before its definition in module: 'tables phase: 1

I've tried reading the doc and can't figure out what I'm doing wrong... So what am I doing wrong?

like image 302
Matt G Avatar asked Nov 19 '25 16:11

Matt G


1 Answers

In order for definitions to be usable during the macro definition phase, use for-syntax:

(require (for-syntax "exceptions.rkt"))
like image 128
Chris Jester-Young Avatar answered Nov 22 '25 17:11

Chris Jester-Young