Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 33s
Complement to foldr-o. The combiner relation has signature
(acc head new-acc) — accumulator first.
Examples:
(foldl-o pluso-i (list 1 2 3 4 5) 0 q) -> (15)
(foldl-o *o-i (list 1 2 3 4) 1 q) -> (24)
(foldl-o (fn (acc x r) (conso x acc r)) ; flipped conso
(list 1 2 3 4) (list) q) -> ((4 3 2 1)) ; reverse
5 new tests, 510/510 cumulative.
49 lines
681 B
Plaintext
49 lines
681 B
Plaintext
;; lib/minikanren/tests/foldl-o.sx — relational left fold.
|
|
|
|
(mk-test
|
|
"foldl-o-empty"
|
|
(run* q (foldl-o pluso-i (list) 42 q))
|
|
(list 42))
|
|
|
|
(mk-test
|
|
"foldl-o-sum"
|
|
(run*
|
|
q
|
|
(foldl-o
|
|
pluso-i
|
|
(list 1 2 3 4 5)
|
|
0
|
|
q))
|
|
(list 15))
|
|
|
|
(mk-test
|
|
"foldl-o-product"
|
|
(run*
|
|
q
|
|
(foldl-o
|
|
*o-i
|
|
(list 1 2 3 4)
|
|
1
|
|
q))
|
|
(list 24))
|
|
|
|
(mk-test
|
|
"foldl-o-reverse-via-flip-conso"
|
|
(run*
|
|
q
|
|
(foldl-o
|
|
(fn (acc x r) (conso x acc r))
|
|
(list 1 2 3 4)
|
|
(list)
|
|
q))
|
|
(list (list 4 3 2 1)))
|
|
|
|
(mk-test
|
|
"foldl-o-with-init"
|
|
(run*
|
|
q
|
|
(foldl-o pluso-i (list 1 2 3) 100 q))
|
|
(list 106))
|
|
|
|
(mk-tests-run!)
|