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: Pascal J. Bourguignon
Subject: Re: How to delete all nil properties from a plist?
Date: Sun, 02 Aug 2015 03:36:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> 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))

This is horrible. Again, you can't prevent yourself writing O(n²) code
when O(n) would do perfectly.




-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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