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:
@@ -277,6 +277,14 @@
|
||||
((nullo l1) (nullo l2) (nullo pairs))
|
||||
((fresh (a1 d1 a2 d2 d-pairs) (conso a1 d1 l1) (conso a2 d2 l2) (conso (list a1 a2) d-pairs pairs) (pairlisto d1 d2 d-pairs))))))
|
||||
|
||||
(define
|
||||
zip-with-o
|
||||
(fn
|
||||
(rel l1 l2 result)
|
||||
(conde
|
||||
((nullo l1) (nullo l2) (nullo result))
|
||||
((fresh (a1 d1 a2 d2 a-result d-result) (conso a1 d1 l1) (conso a2 d2 l2) (rel a1 a2 a-result) (conso a-result d-result result) (zip-with-o rel d1 d2 d-result))))))
|
||||
|
||||
(define
|
||||
swap-firsto
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user