Make TR's for/hash
form more flexible
This commit is contained in:
parent
58a3d12f0c
commit
d35fb82f4a
|
@ -1086,7 +1086,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
(syntax-parse stx
|
(syntax-parse stx
|
||||||
#:literals (:)
|
#:literals (:)
|
||||||
((_ (~seq : return-annotation:expr)
|
[(_ (~seq : return-annotation:expr)
|
||||||
clause:for-clauses
|
clause:for-clauses
|
||||||
body ...) ; body is not always an expression, can be a break-clause
|
body ...) ; body is not always an expression, can be a break-clause
|
||||||
(quasisyntax/loc stx
|
(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)))
|
((return-hash : return-annotation (ann (#,hash-maker null) return-annotation)))
|
||||||
(clause.expand ... ...)
|
(clause.expand ... ...)
|
||||||
(let-values (((key val) (let () body ...)))
|
(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/hash: (define-for/hash:-variant #'make-immutable-hash))
|
||||||
(define-syntax for/hasheq: (define-for/hash:-variant #'make-immutable-hasheq))
|
(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))]))
|
(quasisyntax/loc stx (#,l/c k.ann-name . body))]))
|
||||||
(values (mk #'let/cc) (mk #'let/ec))))
|
(values (mk #'let/cc) (mk #'let/ec))))
|
||||||
|
|
||||||
|
|
||||||
;; lambda with optional type annotations, uses syntax properties
|
;; lambda with optional type annotations, uses syntax properties
|
||||||
(define-syntax (-lambda stx)
|
(define-syntax (-lambda stx)
|
||||||
(syntax-parse stx
|
(syntax-parse stx
|
||||||
|
|
|
@ -2039,6 +2039,14 @@
|
||||||
(foo #hash(("foo" . foo))))
|
(foo #hash(("foo" . foo))))
|
||||||
(-HT -Symbol -String)]
|
(-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
|
;; call-with-input-string and friends - PR 14050
|
||||||
[tc-e (call-with-input-string "abcd" (lambda: ([input : Input-Port]) (values 'a 'b)))
|
[tc-e (call-with-input-string "abcd" (lambda: ([input : Input-Port]) (values 'a 'b)))
|
||||||
#:ret (ret (list (-val 'a) (-val 'b)))]
|
#:ret (ret (list (-val 'a) (-val 'b)))]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user