Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #lang racket/base
  2.  
  3. (require
  4. racket/base
  5. racket/include
  6. racket/require-syntax
  7.  
  8. (for-syntax racket/base)
  9. (for-syntax racket/list)
  10. (for-syntax racket/match)
  11. (for-syntax racket/path)
  12. (for-syntax syntax/stx))
  13.  
  14. (define-syntax (_#%module-begin stx)
  15. (if (eq? 'module-begin (syntax-local-context))
  16. (syntax-case stx ()
  17. [(_#%module-begin . forms)
  18. (let ([expanded-code (local-expand #'(#%plain-module-begin . forms)
  19. 'module-begin '())])
  20. (with-syntax ([(body ...) (map maybe-muted (cdr (stx->list expanded-code)))])
  21. (syntax/loc stx (#%module-begin
  22. body ...
  23. ))))])
  24. (raise-syntax-error #f "allowed only around a module body" stx)))
  25.  
  26. (define-for-syntax (maybe-muted stx)
  27. (syntax-case stx ()
  28. ;; [(module . x) stx]
  29. [form #'(mute form)]))
  30.  
  31. (define-syntax (mute stx)
  32. (syntax-case stx ()
  33. [(_ form)
  34. #'form]))
  35.  
  36. (provide
  37. (for-syntax (all-from-out racket/base))
  38.  
  39. (except-out (all-from-out racket/base)
  40. #%module-begin)
  41.  
  42. (rename-out [_#%module-begin #%module-begin]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement