Added the for:, for/list:, etc macros.
This commit is contained in:
parent
23f30af459
commit
5213f54f56
17
collects/typed-scheme/private/for-clauses.rkt
Normal file
17
collects/typed-scheme/private/for-clauses.rkt
Normal 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)))
|
|
@ -39,7 +39,8 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
(private internal)
|
(private internal)
|
||||||
(except-in (utils utils tc-utils))
|
(except-in (utils utils tc-utils))
|
||||||
(env type-name-env)
|
(env type-name-env)
|
||||||
"type-contract.rkt"))
|
"type-contract.rkt"
|
||||||
|
"for-clauses.rkt"))
|
||||||
|
|
||||||
(require (utils require-contract)
|
(require (utils require-contract)
|
||||||
"colon.rkt"
|
"colon.rkt"
|
||||||
|
@ -378,6 +379,35 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
c ...)
|
c ...)
|
||||||
ty))]))
|
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)
|
(define-syntax (provide: stx)
|
||||||
(syntax-parse stx
|
(syntax-parse stx
|
||||||
[(_ [i:id t] ...)
|
[(_ [i:id t] ...)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user