[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to delete all nil properties from a plist?
From: |
John Mastro |
Subject: |
Re: How to delete all nil properties from a plist? |
Date: |
Wed, 5 Aug 2015 18:05:17 -0700 |
> 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) ))
I took a swing at this too for the fun of it. Here's what I ended
up with:
(defun plist-drop-nil-props (plist)
(let* ((result (list 'head))
(last result))
(cl-loop for (key val) on plist by #'cddr do
(when-let (new (and val (list key val)))
(setcdr last new)
(setq last (cdr new))))
(cdr result)))
The `when-let' macro is new in Emacs 25 but obviously it can be
trivially replaced with `let' and `when' (or `-when-let' from
dash.el).
--
john
- Re: How to delete all nil properties from a plist?, (continued)
- 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, 2015/08/05
- Re: How to delete all nil properties from a plist?,
John Mastro <=
- 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
Message not available