Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created October 26, 2012 21:13
Show Gist options
  • Save dyoo/3961569 to your computer and use it in GitHub Desktop.
Save dyoo/3961569 to your computer and use it in GitHub Desktop.
getting the names out of #%kernel
#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