Created
August 23, 2016 21:09
-
-
Save bmastenbrook/6629ca93828d4e94888c16e05cd7063a to your computer and use it in GitHub Desktop.
I heard you like macros
This file contains 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 | |
(require (for-syntax racket)) | |
(require (for-syntax racket/stxparam)) | |
(begin-for-syntax | |
(define-syntax-parameter macro-stx (lambda (stx) (raise-syntax-error #f "use of macro-stx outside of macro" stx)))) | |
(define-syntax macro | |
(syntax-rules () | |
[(_ e) | |
(let-syntax ([foo (lambda (stx) | |
(syntax-parameterize ([macro-stx (make-rename-transformer #'stx)]) | |
e))]) | |
(foo))])) | |
(define-for-syntax x 42) | |
(macro (datum->syntax macro-stx x)) | |
(let ([x 1]) | |
(macro (datum->syntax macro-stx #'x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment