Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created March 28, 2013 21:34
Show Gist options
  • Save dyoo/5267007 to your computer and use it in GitHub Desktop.
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.
#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