mk: nub-o — dedupe by keeping the last occurrence
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 56s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 56s
Walks the list; if the head appears in the tail (membero), drop it and recurse; otherwise keep it and recurse. Result preserves only the *last* occurrence of each value. Caveat: with input like (1 1 1) the membero check succeeds with multiplicity, so multiple (1) answers may emerge — each is shape- identical, but the test deliberately checks every-result-is-(1) rather than asserting answer count. 5 new tests, 526/526 cumulative.
This commit is contained in:
@@ -80,6 +80,15 @@
|
||||
((nullo l) (nullo result))
|
||||
((fresh (a d a-result rest-result) (conso a d l) (rel a a-result) (flat-mapo rel d rest-result) (appendo a-result rest-result result))))))
|
||||
|
||||
(define
|
||||
nub-o
|
||||
(fn
|
||||
(l result)
|
||||
(conde
|
||||
((nullo l) (nullo result))
|
||||
((fresh (a d r-rest) (conso a d l) (conde ((membero a d) (nub-o d result)) ((nafc (membero a d)) (conso a r-rest result) (nub-o d r-rest))))))))
|
||||
|
||||
|
||||
(define
|
||||
membero
|
||||
(fn
|
||||
@@ -88,7 +97,6 @@
|
||||
((fresh (d) (conso x d l)))
|
||||
((fresh (a d) (conso a d l) (membero x d))))))
|
||||
|
||||
|
||||
(define
|
||||
not-membero
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user