Skip to content

Instantly share code, notes, and snippets.

@samth
Created June 25, 2012 21:00
Show Gist options
  • Save samth/2991214 to your computer and use it in GitHub Desktop.
Save samth/2991214 to your computer and use it in GitHub Desktop.
Trouble with state and module-begin
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment