public
Created

Trouble with state and module-begin

  • Download Gist
mb-st.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#lang racket/load
 
(module st racket
(define is-typed? (box #f))
(define type-env (box 0))
(provide is-typed? type-env))
 
(module mac racket
(require (for-syntax 'st))
(define-syntax (m stx)
(unless (> (unbox type-env) 0)
(displayln ">> type-env is 0")
(error 'fail))
#'#t)
(provide m))
 
(module lang racket
(require (for-syntax 'st))
(provide (rename-out [mb #%module-begin])
(except-out (all-from-out racket) #%module-begin))
(define-syntax (mb stx)
(displayln ">> in module-begin")
(set-box! is-typed? #t)
(syntax-case stx ()
[(_ forms ...)
#'(#%module-begin
forms ...
(begin-for-syntax
(when (unbox is-typed?)
(set-box! type-env 1))))])))
 
(module A1 'lang
(require (for-syntax 'st))
(require 'mac)
(module+ sub
0
(m)))
 
(require 'A1)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.