[plt-scheme] question about transfer of value from transformer to run time
Say I have a module with an option for its tuning. This option will be used both in the transformer and in the run time environment. For example:
(module a mzscheme
;option used both in transformer and run time environment
(define-for-syntax option 1)
(define option 1)
;-----------------
(define-syntax macro-a
(case option
((1) (lambda (stx) #'"the option is 1"))
(else (lambda (stx) #'"the option is not 1"))))
(define proc-a
(case option
((1) (lambda () "the option is 1"))
(else (lambda () "the option is not 1"))))
(provide macro-a proc-a))
(require a)
(macro-a) ; --> "the option is 1"
(proc-a) ; --> "the option is 1"
However, I dont find it elegant to have two definitions for conceptually the same option. The standard solution would be:
(module option mzscheme
(define option 1)
(provide option))
(module b mzscheme
;option used both in transformer and run time environment
(require-for-syntax option)
(require option)
;-----------------
(define-syntax macro-b
(case option
((1) (lambda (stx) #'"the option is 1"))
(else (lambda (stx) #'"the option is not 1"))))
(define proc-b
(case option
((1) (lambda () "the option is 1"))
(else (lambda () "the option is not 1"))))
(provide macro-b proc-b))
(require b)
(macro-b) ; --> "the option is 1"
(proc-b) ; --> "the option is 1"
But now the definition of the option is separated from the module, which I dont like too much. So I came up with the following.
(module c mzscheme
;option used both in transformer and run time environment
(define-for-syntax option 2)
(define-syntax (transfer stx)
(syntax-local-introduce #`(define option (#%datum . #,option))))
(transfer)
;--------------------------------------------------------
(define-syntax macro-c
(case option
((1) (lambda (stx) #'"the option is 1"))
(else (lambda (stx) #'"the option is not 1"))))
(define proc-c
(case option
((1) (lambda () "the option is 1"))
(else (lambda () "the option is not 1"))))
(provide macro-c proc-c))
(require c)
(macro-c) ; --> "the option is not 1"
(proc-c) ; --> "the option is not 1"
This seems to do what I want, but it seems a little bit tricky too. Can I trust the approach in module c, or is the approach in modules a and b safer?
Best wishes, Jos koot.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070617/96b62346/attachment.html>