[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" <pjb@informatimago.com>
writes:
> 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)
(nil-prop)
(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
http://user.it.uu.se/~embe8573
- Re: How to delete all nil properties from a plist?, (continued)
- Re: How to delete all nil properties from a plist?, Marcin Borkowski, 2015/08/01
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/01
- Message not available
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/02
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/05
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/05
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/05
- Re: How to delete all nil properties from a plist?,
Emanuel Berg <=
- Re: How to delete all nil properties from a plist?, John Mastro, 2015/08/05
- Re: How to delete all nil properties from a plist?, John Mastro, 2015/08/05
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/05
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/07
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/05
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/07
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/08
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/08
- Message not available
- Re: How to delete all nil properties from a plist?, Pascal J. Bourguignon, 2015/08/08
- Re: How to delete all nil properties from a plist?, Emanuel Berg, 2015/08/08