diff --git a/collects/typed-racket/base-env/for-clauses.rkt b/collects/typed-racket/base-env/for-clauses.rkt index 3e36b812..75c2d604 100644 --- a/collects/typed-racket/base-env/for-clauses.rkt +++ b/collects/typed-racket/base-env/for-clauses.rkt @@ -8,6 +8,7 @@ ;; intersperses "#:when #t" clauses to emulate the for* variants' semantics (define-splicing-syntax-class for-clause + #:description "for clause" ;; single-valued seq-expr (pattern (~and c (var:optionally-annotated-name seq-expr:expr)) #:with (expand ...) #`(#,(syntax/loc #'c @@ -25,3 +26,18 @@ (pattern (~seq (~and kw (~or #:when #:unless #:break #:final)) guard:expr) #:with (expand ...) (list #'kw #'guard) #:with (expand* ...) #'(expand ...))) + +(define-syntax-class for-clauses + #:description "for clauses" + #:attributes ((expand 2) (expand* 2)) + (pattern (:for-clause ...))) + +(define-syntax-class accumulator-binding + #:description "accumumulator binding" + #:attributes (ann-name init ty) + (pattern (:annotated-name init:expr))) + +(define-syntax-class accumulator-bindings + #:description "accumumulator bindings" + #:attributes ((ann-name 1) (init 1) (ty 1)) + (pattern (:accumulator-binding ...))) diff --git a/collects/typed-racket/base-env/prims.rkt b/collects/typed-racket/base-env/prims.rkt index 44816fd7..b606f4ef 100644 --- a/collects/typed-racket/base-env/prims.rkt +++ b/collects/typed-racket/base-env/prims.rkt @@ -791,7 +791,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (lambda (stx) (syntax-parse stx #:literals (:) [(_ a:optional-standalone-annotation - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (maybe-annotate-body (quasisyntax/loc stx @@ -823,7 +823,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (syntax-parse stx #:literals (:) [(_ : ty ((var:optionally-annotated-name) ...) - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (syntax-property (quasisyntax/loc stx @@ -833,7 +833,7 @@ This file defines two sorts of primitives. All of them are provided into any mod 'type-ascription #'ty)] [(_ ((var:annotated-name) ...) - (clause:for-clause ...) + clause:for-clauses c ...) (syntax-property (quasisyntax/loc stx @@ -846,7 +846,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (syntax-parse stx #:literals (:) [(_ : ty ((var:optionally-annotated-name init:expr) ...) - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (syntax-property (quasisyntax/loc stx @@ -855,22 +855,22 @@ This file defines two sorts of primitives. All of them are provided into any mod c ...)) 'type-ascription #'ty)] - [(_ ((var:annotated-name init:expr) ...) - (clause:for-clause ...) + [(_ accum:accumulator-bindings + clause:for-clauses c ...) (syntax-property (quasisyntax/loc stx - (for/fold ((var.ann-name init) ...) + (for/fold ((accum.ann-name accum.init) ...) (clause.expand ... ...) c ...)) 'type-ascription - #'(values var.ty ...))])) + #'(values accum.ty ...))])) (define-syntax (for*: stx) (syntax-parse stx #:literals (:) [(_ (~seq : Void) ... - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (quasisyntax/loc stx (for: (clause.expand* ... ...) @@ -881,7 +881,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (lambda (stx) (syntax-parse stx #:literals (:) [(_ a:optional-standalone-annotation - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (maybe-annotate-body (quasisyntax/loc stx @@ -907,7 +907,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (syntax-parse stx #:literals (:) [(_ : ty ((var:optionally-annotated-name) ...) - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (syntax-property (quasisyntax/loc stx @@ -917,7 +917,7 @@ This file defines two sorts of primitives. All of them are provided into any mod 'type-ascription #'ty)] [(_ ((var:annotated-name) ...) - (clause:for-clause ...) + clause:for-clauses c ...) (syntax-property (quasisyntax/loc stx @@ -930,7 +930,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (syntax-parse stx #:literals (:) [(_ : ty ((var:optionally-annotated-name init:expr) ...) - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (syntax-property (quasisyntax/loc stx @@ -940,7 +940,7 @@ This file defines two sorts of primitives. All of them are provided into any mod 'type-ascription #'ty)] [(_ ((var:annotated-name init:expr) ...) - (clause:for-clause ...) + clause:for-clauses c ...) (syntax-property (quasisyntax/loc stx @@ -954,7 +954,7 @@ This file defines two sorts of primitives. All of them are provided into any mod (lambda (stx) (syntax-parse stx #:literals (:) [(_ a:optional-standalone-annotation - (clause:for-clause ...) + clause:for-clauses c ...) ; c is not always an expression, can be a break-clause (cond [(syntax-e #'a.ty)