Created
October 26, 2012 21:13
-
-
Save dyoo/3961569 to your computer and use it in GitHub Desktop.
getting the names out of #%kernel
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/base | |
(require racket/set | |
rackunit) | |
;; kernel-variable-exports: (setof symbol) | |
;; Lists the runtime variable exports we inherit from '#%kernel | |
(provide (rename-out [result-from-module->exports | |
kernel-variable-exports])) | |
;; How to get the list of symbols out of #%kernel? | |
;; | |
;; Unfortunately, it doesn't look like we can do this: | |
;; | |
;; (module->namespace ''#%kernel) | |
;; | |
;; Racket reports that the current code inspector isn't powerful | |
;; enough to look at '#%kernel's namespace. | |
;; Ok, alternative plan. It looks like we can do this: | |
(define result-from-module->exports | |
(let-values ([(variables syntax) (module->exports ''#%kernel)]) | |
(map car (cdr (assoc 0 variables))))) | |
;; ... but we can also do this: | |
(define result-from-module-compiled-exports | |
(parameterize ([current-namespace (make-base-namespace)]) | |
(let-values ([(variables syntax) | |
(module-compiled-exports (compile '(module foo '#%kernel | |
(#%provide (all-from '#%kernel)))))]) | |
(map car (cdr (assoc 0 variables)))))) | |
;; Are they the same? | |
(check-equal? (list->set result-from-module->exports) | |
(list->set result-from-module-compiled-exports)) | |
;; If we get here without error, then they are the same thing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment