Created
June 25, 2012 21:00
-
-
Save samth/2991214 to your computer and use it in GitHub Desktop.
Trouble with state and module-begin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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