Skip to content

Instantly share code, notes, and snippets.

@samth
Created March 28, 2014 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samth/9834239 to your computer and use it in GitHub Desktop.
Save samth/9834239 to your computer and use it in GitHub Desktop.
#lang racket
(module m1 racket
(require (for-syntax racket/pretty))
(define-syntax (modbeg stx)
(syntax-case stx ()
[(_ forms ...)
(let ()
(define expanded (local-expand #'(#%plain-module-begin forms ...) 'module-begin null))
(pretty-print (syntax->datum expanded))
(syntax-case expanded ()
[(_ ... (quote last))
(identifier? #'last)
(begin (eprintf "~a\n" (syntax-local-value #'last))
#'(#%plain-module-begin (void)))]
[_ #'(#%plain-module-begin (void))]))]))
(provide (rename-out [modbeg #%module-begin])
(except-out (all-from-out racket) #%module-begin)))
(module m2 (submod ".." m1)
(define-syntax x (lambda (stx) #''x))
x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment