stxparam approach

dev-elider-3
Matthew Butterick 9 years ago
parent 7e605cd081
commit 705ea591b0

@ -5,21 +5,18 @@
(all-defined-out)) (all-defined-out))
(require (for-syntax racket/syntax racket/list br/datum)) (require (for-syntax racket/syntax racket/list br/datum))
(define-for-syntax alphasyms (for/list ([i (in-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ")]) (require racket/stxparam)
(string->symbol (format "~a" i)))) (define-syntax-parameter A
(define-for-syntax stringsyms (map (λ(s) (format-datum "~a$" s)) alphasyms)) (λ (stx)
(raise-syntax-error (syntax-e stx) "can only be used inside the place")))
(define-syntax (basic-module-begin stx)
(syntax-case stx () (define #'(basic-module-begin PARSE-TREE ...)
[(_ PARSE-TREE ...)
(with-syntax ([(VARNAME ...) (datum->syntax stx alphasyms)]
[(STRINGVARNAME ...) (datum->syntax stx stringsyms)])
#'(#%module-begin #'(#%module-begin
(define VARNAME 0) ... (let ([A-inner 0])
(define STRINGVARNAME "") ... (syntax-parameterize
(provide VARNAME ... STRINGVARNAME ...) ([A (make-rename-transformer #'A-inner)])
(println (quote PARSE-TREE ...)) (println (quote PARSE-TREE ...))
PARSE-TREE ...))])) PARSE-TREE ...))))
; #%app and #%datum have to be present to make #%top work ; #%app and #%datum have to be present to make #%top work
(define #'(basic-top . id) (define #'(basic-top . id)

Loading…
Cancel
Save