Added the for:, for/list:, etc macros.

original commit: 5213f54f56e6d9d1a14b16fd0348495a20a648e9
This commit is contained in:
Vincent St-Amour 2010-05-26 17:24:31 -04:00
parent 3bbf39b86a
commit 312671d85d
2 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,17 @@
#lang scheme/base
(require syntax/parse
"annotate-classes.rkt")
(provide for-clause)
(define-splicing-syntax-class for-clause
;; single-valued seq-expr
(pattern (var:annotated-name seq-expr:expr)
#:with (expand ...) (list #'(var.ann-name seq-expr)))
;; multi-valued seq-expr
(pattern ((var:annotated-name ...) seq-expr:expr)
#:with (expand ...) (list #'((var.ann-name ...) seq-expr)))
;; when clause
(pattern (~seq #:when guard:expr)
#:with (expand ...) (list #'#:when #'guard)))

View File

@ -39,7 +39,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
(private internal)
(except-in (utils utils tc-utils))
(env type-name-env)
"type-contract.rkt"))
"type-contract.rkt"
"for-clauses.rkt"))
(require (utils require-contract)
"colon.rkt"
@ -378,6 +379,35 @@ This file defines two sorts of primitives. All of them are provided into any mod
c ...)
ty))]))
(define-for-syntax (define-for-variant name)
(lambda (stx)
(syntax-parse stx #:literals (:)
[(_ : ty
(clause:for-clause ...)
c:expr ...)
(quasisyntax/loc
stx
(ann (#,name
(clause.expand ... ...)
c ...)
ty))])))
(define-syntax (define-for-variants stx)
(syntax-parse stx
[(_ (name untyped-name) ...)
(quasisyntax/loc
stx
(begin (define-syntax name (define-for-variant #'untyped-name)) ...))]))
(define-for-variants
(for: for)
(for/list: for/list)
(for/hash: for/hash)
(for/hasheq: for/hasheq)
(for/hasheqv: for/hasheqv)
(for/and: for/and)
(for/or: for/or)
(for/first: for/first)
(for/last: for/last))
(define-syntax (provide: stx)
(syntax-parse stx
[(_ [i:id t] ...)