Last active
December 15, 2015 18:30
-
-
Save dyoo/5304560 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
(require (for-syntax syntax/boundmap | |
syntax/parse)) | |
(begin-for-syntax | |
(define const-table (make-free-identifier-mapping))) | |
(define-syntax (define-int-constant stx) | |
(syntax-parse stx | |
[(_ name:id v:integer) | |
#'(begin | |
(define-syntax name | |
(lambda (stx) | |
(cond [(identifier? stx) | |
#'v] | |
[else | |
(raise-syntax-error #f "Can't apply the integer constant" stx)]))) | |
(begin-for-syntax | |
(free-identifier-mapping-put! const-table #'name #'v)))])) | |
(define-syntax (peek stx) | |
(syntax-parse stx | |
[(_ name:id) | |
(begin | |
(define compile-time-value | |
(free-identifier-mapping-get const-table #'name (lambda () #'#f))) | |
(printf "At compile time, I see ~s is ~s\n" #'name compile-time-value) | |
#'name)])) | |
(define-int-constant x 42) | |
(peek x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment