pull/2/head
Matthew Butterick 9 years ago
parent 2d5db8afb5
commit 51ff735f7d

@ -61,18 +61,18 @@
(define-syntax (cases stx)
(syntax-case stx (else)
[(_ <base-type> <input-var>
[<subtype> (<positional-var> ...) <body> ...] ...
[else <else-body> ...])
(inject-syntax ([#'(<subtype?> ...) (map-syntax (λ(s) (format-datum '~a? s)) #'(<subtype> ...))])
[(_ _base-type _input-var
[_subtype (_positional-var ...) . _body] ...
[else . _else-body])
(inject-syntax ([#'(_subtype? ...) (suffix-ids #'(_subtype ...) "?")])
#'(cond
[(<subtype?> <input-var>) (match-let ([(list <positional-var> ...) (struct->list <input-var>)])
<body> ...)] ...
[else <else-body> ...]))]
[(_ <base-type> <input-var>
<subtype-case> ...)
#'(cases <base-type> <input-var>
<subtype-case> ...
[(_subtype? _input-var) (match-let ([(list _positional-var ...) (struct->list _input-var)])
. _body)] ...
[else . _else-body]))]
[(_ _base-type _input-var
_subtype-case ...)
#'(cases _base-type _input-var
_subtype-case ...
[else (void)])]))

@ -3,12 +3,12 @@
(define #'(introduce-scope _color . _parents)
(with-syntax ([color #'_color]
[color-string (format "~a" (syntax->datum #'_color))]
[color:define (format-id #f "~a:define" #'_color)]
[color:id (format-id #f "~a:id" #'_color)]
[color-binding-id (format-id #f "~a-binding-id" #'_color)]
[color-binding-form (format-id #f "~a-binding-form" #'_color)]
[color-id (format-id #f "~a-id" #'_color)]
[color-string (format-string "~a" #'_color)]
[color:define (suffix-id #'_color ":define")]
[color:id (suffix-id #'_color ":id")]
[color-binding-id (suffix-id #'_color "-binding-id")]
[color-binding-form (suffix-id #'_color "-binding-form")]
[color-id (suffix-id #'_color "-id")]
[module-name (generate-temporary)]
[parents (if (pair? (syntax->list #'_parents))
(car (syntax->list #'_parents))
@ -16,16 +16,16 @@
(replace-context #'_color
#'(begin
(module module-name br
(require (for-syntax br/datum br/syntax))
(require (for-syntax br/datum br/scope))
(provide (for-syntax (all-defined-out)) (all-defined-out))
(begin-for-syntax
(define-scope color parents))
(define #'(color:define _id-in _expr)
(with-syntax* ([color:id (shared-syntax (format-datum "~a:~a" color-string #'_id-in))]
[color-binding-id (color-binding-form #'_id-in)]
[color-id (color #'color-binding-id)])
(inject-syntax* ([#'color:id (shared-syntax (prefix-id color-string ":" #'_id-in))]
[#'color-binding-id (color-binding-form #'_id-in)]
[#'color-id (color #'color-binding-id)])
#'(begin
(define color-binding-id _expr)
(define-syntax color:id

Loading…
Cancel
Save