help-gnu-emacs
[Top][All Lists]
Advanced

[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: Sun, 02 Aug 2015 03:32:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <mbork@mbork.pl> writes:

>> Hi all, so I'm still using plists, though I'm less
>> and less sure that they are actually better than
>> alists for my use-case. Now I need to delete all
>> properties whose value is nil. I'm using this
>> function:

Try this:

(require 'cl)

(defun plist-drop-nil-props (l)
  (let((new)
       (prop nil) )
    (cl-loop for x in l
             do (if (or (setq prop (not prop)) x)
                    (setq new (append new (list x)))
                  (setq new (butlast new))))
    new))

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

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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