Commit 22664deb authored by Philipp Marek's avatar Philipp Marek

Added DELETE-FROM-PLIST*

parent cc39718f
(in-package :alexandria-2)
(defun delete-from-plist* (plist &rest keys)
"Just like REMOVE-FROM-PLIST, but this version may destructively modify the
provided PLIST.
The second return value is an alist of the removed items, in unspecified order."
;; TODO: a plist?
(declare (optimize speed))
(loop with head = plist
with tail = nil ; a nil tail means an empty result so far
with kept = ()
for (key . rest) on plist by #'cddr
do (assert rest () "Expected a proper plist, got ~S" plist)
(if (member key keys :test #'eq)
;; skip over this pair
(let ((next (cdr rest)))
(push (cons key rest)
kept)
(if tail
(setf (cdr tail) next)
(setf head next)))
;; keep this pair
(setf tail rest))
finally (return (values head kept))))
......@@ -5,4 +5,6 @@
(:lock t)
(:export .
#. (let (res) (do-external-symbols (sym :alexandria.1.0.0) (push sym res)) res)
#:delete-from-plist*
))
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