File tree Expand file tree Collapse file tree 3 files changed +63
-2
lines changed Expand file tree Collapse file tree 3 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 37
37
(define-qi-syntax-rule (none onex:clause)
38
38
(not (any onex)))
39
39
40
+ (define-qi-syntax-parser zip
41
+ [(_ op:clause) #'(~zip op __)]
42
+ [_:id #'(zip list)])
43
+
40
44
(define-qi-syntax-parser NOR
41
45
[_:id #'(~> OR NOT)])
42
46
Original file line number Diff line number Diff line change 10
10
~any?
11
11
~none?
12
12
~count
13
- ~live?)
13
+ ~live?
14
+ ~zip)
14
15
15
16
(define (->boolean v) (and v #t ))
16
17
39
40
40
41
(define (~live? . args)
41
42
(not (null? args)))
43
+
44
+ (define (zip-lists op lsts)
45
+ (if (null? lsts)
46
+ null
47
+ (if (ormap null? lsts)
48
+ null
49
+ (let ([vs (map car lsts)])
50
+ (cons (apply op vs)
51
+ (zip-lists op (map cdr lsts)))))))
52
+
53
+ (define (~zip op . lsts)
54
+ (apply values (zip-lists op lsts)))
Original file line number Diff line number Diff line change 1565
1565
'("ba " "ca " "da " )
1566
1566
"clos respects threading direction at the site of definition " )
1567
1567
(check-equal? ((☯ (~> (-< (~> second (clos *)) _ ) map)) (list 1 2 3 ))
1568
- '(2 4 6 ))))
1568
+ '(2 4 6 )))
1569
+
1570
+ (test-suite
1571
+ "zip "
1572
+ (test-equal? "lists of the same size "
1573
+ ((☯ (~> zip ▽))
1574
+ '(a b c) '(1 2 3 ))
1575
+ '((a 1 ) (b 2 ) (c 3 )))
1576
+ (test-equal? "lists of different sizes truncates at shortest list "
1577
+ ((☯ (~> zip ▽))
1578
+ '(a b) '(1 2 3 ))
1579
+ '((a 1 ) (b 2 )))
1580
+ (test-equal? "lists of different sizes truncates at shortest list "
1581
+ ((☯ (~> zip ▽))
1582
+ '(a b c) '(1 2 ))
1583
+ '((a 1 ) (b 2 )))
1584
+ (test-equal? "any empty list causes no values to be returned "
1585
+ ((☯ (~> zip ▽))
1586
+ '() '(1 2 3 ))
1587
+ null)
1588
+ (test-equal? "any empty list causes no values to be returned "
1589
+ ((☯ (~> zip ▽))
1590
+ '(a b c) '() )
1591
+ null)
1592
+ (test-equal? "more than two lists "
1593
+ ((☯ (~> zip ▽))
1594
+ '(a b c) '(1 2 3 ) '(P Q R))
1595
+ '((a 1 P) (b 2 Q) (c 3 R)))
1596
+ (test-equal? "just one list "
1597
+ ((☯ (~> zip ▽))
1598
+ '(a b c))
1599
+ '((a) (b) (c)))
1600
+ (test-equal? "no lists "
1601
+ ((☯ (~> zip ▽)))
1602
+ null)
1603
+
1604
+ (test-equal? "zip with primitive operation "
1605
+ ((☯ (~> (zip +) ▽))
1606
+ '(1 2 ) '(3 4 ))
1607
+ '(4 6 ))
1608
+ ;; (test-equal? "zip with flow operation"
1609
+ ;; ((☯ (~> (zip (~> string->number +)) ▽))
1610
+ ;; '("1" "2") '("3" "4"))
1611
+ ;; '(4 6))
1612
+ ))
1569
1613
1570
1614
(test-suite
1571
1615
"language extension "
You can’t perform that action at this time.
0 commit comments