Add #:unless to the for: macros.

This commit is contained in:
Vincent St-Amour 2012-06-25 13:38:51 -04:00
parent b1ad108759
commit 972df7c89e
2 changed files with 22 additions and 2 deletions

View File

@ -37,6 +37,13 @@
#:when (odd? i))
(+ i j 10))
'(21 43))
(check equal?
(for/list: : (Listof Integer)
((i : Integer '(1 2 3))
(j : Integer '(10 20 30))
#:unless (odd? i))
(+ i j 10))
'(32))
(check equal?
(for/or: : Boolean
@ -113,6 +120,15 @@
(k : Integer '(100 200 300)))
(+ acc i j k))
1998)
(check =
(for*/fold: : Integer
((acc : Integer 0))
((i : Integer '(1 2 3))
#:unless (even? i)
(j : Integer '(10 20 30))
(k : Integer '(100 200 300)))
(+ acc i j k))
3996)
(check =
(for/sum: : Integer

View File

@ -21,7 +21,9 @@
((v.ann-name ...) seq-expr))))
;; when clause
(pattern (~seq #:when guard:expr)
#:with (expand ...) (list #'#:when #'guard)))
#:with (expand ...) (list #'#:when #'guard))
(pattern (~seq #:unless guard:expr)
#:with (expand ...) (list #'#:unless #'guard)))
;; intersperses "#:when #t" clauses to emulate the for* variants' semantics
(define-splicing-syntax-class for*-clause
@ -40,4 +42,6 @@
#'#:when #'#t))
;; when clause
(pattern (~seq #:when guard:expr)
#:with (expand ...) (list #'#:when #'guard)))
#:with (expand ...) (list #'#:when #'guard))
(pattern (~seq #:unless guard:expr)
#:with (expand ...) (list #'#:unless #'guard)))