generalizations

dev-elider-3
Matthew Butterick 9 years ago
parent e16bb4c480
commit 1aea686c88

@ -13,11 +13,13 @@
(define-syntax format-datum
(λ(stx)
(syntax-case stx (quote datum)
[(_ (quote datum-template) arg ...)
#'(format-datum (datum datum-template) arg ...)]
[(_ (datum datum-template) arg ...)
[(_ (quote <datum-template>) <arg> ...)
#'(format-datum (datum <datum-template>) <arg> ...)]
[(_ (datum datum-template) <arg> ...)
(syntax-let ([#'format-string (format "~a" (syntax->datum #'datum-template))])
#'(string->datum (apply format format-string (list arg ...))))])))
#'(string->datum (apply format format-string (map (λ(arg) (if (syntax? arg)
(syntax->datum arg)
arg)) (list <arg> ...)))))])))
(module+ test

@ -10,10 +10,10 @@
(syntax-parse stx
#:literals (syntax)
[(_ (syntax (id pat-arg ...)) body ...) ; (define #'(foo arg) #'(+ arg arg))
[(_ (syntax (id pat-arg ... . rest-arg)) body ...) ; (define #'(foo arg) #'(+ arg arg))
#'(define-syntax id (λ (stx)
(syntax-case stx ()
[(_ pat-arg ...) body ...])))]
[(_ pat-arg ... . rest-arg) body ...])))]
[(_ sid:syntaxed-id sid2:syntaxed-id) ; (define #'f1 #'f2)
#'(define-syntax sid.name (make-rename-transformer sid2))]

@ -17,4 +17,12 @@
(define-syntax inject-syntax (make-rename-transformer #'add-syntax))
(define-syntax (map-syntax stx)
(syntax-case stx ()
[(_ <proc> <arg> ...)
#'(map <proc> (if (and (syntax? <arg>) (list? (syntax-e <arg>)))
(syntax->list <arg>)
<arg>) ...)]))
#;(define-syntax syntax-variable (make-rename-transformer #'format-id))
Loading…
Cancel
Save