Commit 57badd5e authored by Nikodemus Siivola's avatar Nikodemus Siivola

REMOVE-KEYS renamed to SANS, with new --arguably better-- argument order

parent c14545ea
......@@ -132,7 +132,7 @@ terms and conditions:
@include include/fun-alexandria-lastcar.texinfo
@include include/fun-alexandria-make-circular-list.texinfo
@include include/fun-alexandria-ensure-list.texinfo
@include include/fun-alexandria-remove-keys.texinfo
@include include/fun-alexandria-sans.texinfo
@include include/fun-alexandria-mappend.texinfo
@include include/fun-alexandria-set-equal.texinfo
......
......@@ -90,18 +90,20 @@ expected-type designator of a TYPE-ERROR."
list
(list list)))
(defun remove-keys (keys plist)
"Returns a fresh propery-list with same keys and values as PLIST, except
that keys in the list designated by KEYS and values corresponding to them are
removed."
(defun sans (plist &rest keys)
"Returns a propery-list with same keys and values as PLIST, except that keys
in the list designated by KEYS and values corresponding to them are removed.
The returned property-list may share structure with the PLIST, but PLIST is
not destructively modified."
;; FIXME: unoptimal: (sans '(:a 1 :b 2) :a) has no need to copy the
;; tail.
(do ((new nil)
(tail plist (cddr tail)))
((endp tail)
(nreverse new))
(let ((key (car tail)))
(unless (member key keys)
(push key new)
(push (cadr tail) new)))))
(setf new (list* (cadr tail) key new))))))
(defun mappend (function &rest lists)
"Applies FUNCTION to respective element(s) of each LIST, appending all the
......
......@@ -30,7 +30,7 @@
#:proper-list-p
#:proper-list
#:mappend
#:remove-keys
#:sans
#:set-equal
;; Numbers
#:clamp
......
......@@ -342,17 +342,16 @@
(ensure-list y)))
((1) (2)))
(deftest remove-keys.1
(let* ((orig '(a 1 b 2 c 3 d 4))
(copy (copy-seq orig)))
(list (remove-keys '(a c) copy)
(remove-keys '(b d) copy)
(remove-keys '(b) copy)
(remove-keys '(a) copy)
(remove-keys '(d) copy)
(remove-keys '(a b c d) copy)
(remove-keys '(a b c d e) copy)
(equal copy orig)))
(deftest sans.1
(let ((orig '(a 1 b 2 c 3 d 4)))
(list (sans orig 'a 'c)
(sans orig 'b 'd)
(sans orig 'b)
(sans orig 'a)
(sans orig 'd 42 "zot")
(sans orig 'a 'b 'c 'd)
(sans orig 'a 'b 'c 'd 'x)
(equal orig '(a 1 b 2 c 3 d 4))))
((b 2 d 4)
(a 1 c 3)
(a 1 c 3 d 4)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment