From 1aea686c88f2f3bca2d19f0bc6bbd7868fb855e3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 17 Mar 2016 10:14:26 -0700 Subject: [PATCH] generalizations --- br/datum.rkt | 10 ++++++---- br/define.rkt | 4 ++-- br/syntax.rkt | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/br/datum.rkt b/br/datum.rkt index 960d80b..e4930e9 100644 --- a/br/datum.rkt +++ b/br/datum.rkt @@ -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 ) ...) + #'(format-datum (datum ) ...)] + [(_ (datum datum-template) ...) (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 ...)))))]))) (module+ test diff --git a/br/define.rkt b/br/define.rkt index 99f8ca2..2e7e301 100644 --- a/br/define.rkt +++ b/br/define.rkt @@ -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))] diff --git a/br/syntax.rkt b/br/syntax.rkt index ee4b6e6..c2fc8a1 100644 --- a/br/syntax.rkt +++ b/br/syntax.rkt @@ -17,4 +17,12 @@ (define-syntax inject-syntax (make-rename-transformer #'add-syntax)) +(define-syntax (map-syntax stx) + (syntax-case stx () + [(_ ...) + #'(map (if (and (syntax? ) (list? (syntax-e ))) + (syntax->list ) + ) ...)])) + + #;(define-syntax syntax-variable (make-rename-transformer #'format-id)) \ No newline at end of file