Created
March 28, 2013 21:34
-
-
Save dyoo/5267007 to your computer and use it in GitHub Desktop.
A dir-like function that shows several functions for dynamic evaluation in Racket.
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 | |
(provide dir) | |
(define ns (make-base-namespace)) | |
;; Provides a "dir"-like function on a module. | |
(define (dir module-path) | |
(parameterize ([current-namespace ns]) | |
(dynamic-require module-path (void)) ;; make sure _not_ to cause the module to evaluate. | |
(define-values (module-variable-exports module-syntax-exports) | |
(module->exports module-path)) | |
(define phase-0-variable-exports | |
(for/first ([phase+export module-variable-exports] | |
#:when (= (car phase+export) 0)) | |
(cdr phase+export))) | |
(for/list ([export phase-0-variable-exports]) | |
(define exported-name (car export)) | |
exported-name))) | |
(dir (build-path ;; put a file path here. | |
"dir.rkt" ;; We'l be silly and reflect on ourselves. :) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment