[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to delete all nil properties from a plist?

From: Emanuel Berg
Subject: Re: How to delete all nil properties from a plist?
Date: Thu, 06 Aug 2015 02:30:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

"Pascal J. Bourguignon" <address@hidden>

> Also, notice that doing that, or consing onto the
> beginning of the list and calling nreverse when
> you're done are equivalent time-complexity wise.
> There may be some difference re: cache in actual
> contemporaneous computers but it can be seen only on
> very long lists.

This only uses `cons', `cdr', and `nreverse', so it is
linear, right? ("linear" only from going thru the
input list.)

(require 'cl)

(defun plist-drop-nil-props (l)
  (let ((new)
        (prop) )
    (cl-loop for x in l
             do (if (setq prop (not prop))
                    (if x (setq new (cons x new))
                      (setq nil-prop t))
                  (if x
                      (if nil-prop (setq nil-prop nil)
                        (setq new (cons x new))   )
                    (setq new (cdr new) ))))
    (nreverse new) ))

;; (plist-drop-nil-props '(nil 1 a 1 b 2 c nil d nil e 5 g nil h) )
;; => (a 1 b 2 e 5 h)

So the list so far:

linear: butlast, append
constant: cons, cdr, nreverse

But the OP should probably use yours anyway... :)

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]