mk: zip-with-o — element-wise combine of two lists
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Like Haskell's zipWith but relational. (zip-with-o rel l1 l2 result)
applies a 3-arg combiner relation pointwise: rel l1[i] l2[i] result[i].
(zip-with-o pluso-i (list 1 2 3) (list 10 20 30) q)
-> ((11 22 33))
(zip-with-o (fn (a b r) (== r (list a b))) (list :x :y) (list 1 2) q)
-> (((:x 1) (:y 2)))
Different-length lists fail.
5 new tests, 551/551 cumulative.
This commit is contained in:
52
lib/minikanren/tests/zip-with-o.sx
Normal file
52
lib/minikanren/tests/zip-with-o.sx
Normal file
@@ -0,0 +1,52 @@
|
||||
;; lib/minikanren/tests/zip-with-o.sx — element-wise combine of two lists.
|
||||
|
||||
(mk-test
|
||||
"zip-with-o-empty"
|
||||
(run* q (zip-with-o pluso-i (list) (list) q))
|
||||
(list (list)))
|
||||
|
||||
(mk-test
|
||||
"zip-with-o-pluso-i"
|
||||
(run*
|
||||
q
|
||||
(zip-with-o
|
||||
pluso-i
|
||||
(list 1 2 3)
|
||||
(list 10 20 30)
|
||||
q))
|
||||
(list (list 11 22 33)))
|
||||
|
||||
(mk-test
|
||||
"zip-with-o-times-i"
|
||||
(run*
|
||||
q
|
||||
(zip-with-o
|
||||
*o-i
|
||||
(list 2 3 4)
|
||||
(list 5 6 7)
|
||||
q))
|
||||
(list (list 10 18 28)))
|
||||
|
||||
(mk-test
|
||||
"zip-with-o-different-length-fails"
|
||||
(run*
|
||||
q
|
||||
(zip-with-o
|
||||
pluso-i
|
||||
(list 1 2)
|
||||
(list 1 2 3)
|
||||
q))
|
||||
(list))
|
||||
|
||||
(mk-test
|
||||
"zip-with-o-non-arith-rel"
|
||||
(run*
|
||||
q
|
||||
(zip-with-o
|
||||
(fn (a b r) (== r (list a b)))
|
||||
(list :x :y)
|
||||
(list 1 2)
|
||||
q))
|
||||
(list (list (list :x 1) (list :y 2))))
|
||||
|
||||
(mk-tests-run!)
|
||||
Reference in New Issue
Block a user