Make TR's for/hash form more flexible

This commit is contained in:
Asumu Takikawa 2014-02-20 14:13:41 -05:00
parent 58a3d12f0c
commit d35fb82f4a
2 changed files with 15 additions and 2 deletions

View File

@ -1086,7 +1086,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
(lambda (stx)
(syntax-parse stx
#:literals (:)
((_ (~seq : return-annotation:expr)
[(_ (~seq : return-annotation:expr)
clause:for-clauses
body ...) ; body is not always an expression, can be a break-clause
(quasisyntax/loc stx
@ -1094,7 +1094,11 @@ This file defines two sorts of primitives. All of them are provided into any mod
((return-hash : return-annotation (ann (#,hash-maker null) return-annotation)))
(clause.expand ... ...)
(let-values (((key val) (let () body ...)))
(hash-set return-hash key val))))))))
(hash-set return-hash key val))))]
[(_ clause:for-clauses body ...)
(syntax/loc stx
(for/hash (clause.expand ... ...)
body ...))])))
(define-syntax for/hash: (define-for/hash:-variant #'make-immutable-hash))
(define-syntax for/hasheq: (define-for/hash:-variant #'make-immutable-hasheq))
@ -1148,6 +1152,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
(quasisyntax/loc stx (#,l/c k.ann-name . body))]))
(values (mk #'let/cc) (mk #'let/ec))))
;; lambda with optional type annotations, uses syntax properties
(define-syntax (-lambda stx)
(syntax-parse stx

View File

@ -2039,6 +2039,14 @@
(foo #hash(("foo" . foo))))
(-HT -Symbol -String)]
;; for/hash doesn't always need a return annotation inside
[tc-e (let ()
(tr:define h : (HashTable Any Any)
(for/hash ([(k v) (in-hash #hash(("a" . a)))])
(values v k)))
h)
(-HT Univ Univ)]
;; call-with-input-string and friends - PR 14050
[tc-e (call-with-input-string "abcd" (lambda: ([input : Input-Port]) (values 'a 'b)))
#:ret (ret (list (-val 'a) (-val 'b)))]