@@ -579,48 +579,32 @@ the typed racket language.
579
579
(for/set: for/fold: for/set #f set-add (set) #%expression )
580
580
(for*/set: for*/fold: for*/set #t set-add (set) #%expression )))
581
581
582
- (define-for-syntax (define-for/hash:-variant hash-maker)
583
- (lambda (stx)
584
- (syntax-parse stx
585
- [(_ a1:optional-standalone-annotation*
586
- clause:for-clauses
587
- a2:optional-standalone-annotation*
588
- body ... ) ; body is not always an expression, can be a break-clause
589
- (define a.ty (or (attribute a2.ty) (attribute a1.ty)))
590
- (if a.ty
591
- (quasisyntax/loc stx
592
- (for/fold: : #,a.ty
593
- ((return-hash : #,a.ty (ann (#,hash-maker null) #,a.ty)))
594
- (clause.expand ... ... )
595
- (let-values (((key val) (let () body ... )))
596
- (hash-set return-hash key val))))
597
- (syntax/loc stx
598
- (for/hash (clause.expand ... ... )
599
- body ... )))])))
582
+ (begin-for-syntax
583
+ (define-values (define-for/hash:-variant define-for*/hash:-variant)
584
+ (let ()
585
+ (define ((make for*? for/folder:) hash-maker)
586
+ (lambda (stx)
587
+ (syntax-parse stx
588
+ [(_ a1:optional-standalone-annotation*
589
+ clause:for-clauses
590
+ a2:optional-standalone-annotation*
591
+ body ... ) ; body is not always an expression, can be a break-clause
592
+ (define a.ty (or (attribute a2.ty) (attribute a1.ty) #'(Immutable-HashTable Any Any)))
593
+ (quasisyntax/loc stx
594
+ (#,for/folder: : #,a.ty
595
+ ((return-hash : #,a.ty (ann (#,hash-maker null) #,a.ty)))
596
+ #,(if for*?
597
+ #'(clause.expand* ... ... )
598
+ #'(clause.expand ... ... ))
599
+ (let-values (((key val) (let () body ... )))
600
+ (hash-set return-hash key val))))])))
601
+ (values (make #f #'for/fold: ) (make #t #'for*/fold: )))))
600
602
601
603
(define-syntax for/hash: (define-for/hash:-variant #'make-immutable-hash ))
602
604
(define-syntax for/hasheq: (define-for/hash:-variant #'make-immutable-hasheq ))
603
605
(define-syntax for/hasheqv: (define-for/hash:-variant #'make-immutable-hasheqv ))
604
606
(define-syntax for/hashalw: (define-for/hash:-variant #'make-immutable-hashalw ))
605
607
606
- (define-for-syntax (define-for*/hash:-variant hash-maker)
607
- (lambda (stx)
608
- (syntax-parse stx
609
- #:literals (:)
610
- [(_ a1:optional-standalone-annotation*
611
- clause:for-clauses
612
- a2:optional-standalone-annotation*
613
- body ... ) ; body is not always an expression, can be a break-clause
614
- (define a.ty (or (attribute a2.ty) (attribute a1.ty)))
615
- (quasisyntax/loc stx
616
- (for*/fold: #,@(if a.ty #`(: #,a.ty) #'() )
617
- #,(if a.ty
618
- #`((return-hash : #,a.ty (ann (#,hash-maker null) #,a.ty)))
619
- #`((return-hash (#,hash-maker null))))
620
- (clause.expand* ... ... )
621
- (let-values (((key val) (let () body ... )))
622
- (hash-set return-hash key val))))])))
623
-
624
608
(define-syntax for*/hash: (define-for*/hash:-variant #'make-immutable-hash ))
625
609
(define-syntax for*/hasheq: (define-for*/hash:-variant #'make-immutable-hasheq ))
626
610
(define-syntax for*/hasheqv: (define-for*/hash:-variant #'make-immutable-hasheqv ))
0 commit comments