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: John Mastro
Subject: Re: How to delete all nil properties from a plist?
Date: Wed, 5 Aug 2015 18:07:16 -0700

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

Or the same thing with `while' in place of `cl-loop':

    (defun drop-nil-props (plist)
      (let* ((result (list 'head))
             (last result))
        (while plist
          (let* ((key (pop plist))
                 (val (pop plist))
                 (new (and val (list key val))))
            (when new
              (setcdr last new)
              (setq last (cdr new)))))
        (cdr result)))

-- 
john



reply via email to

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