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 01:46:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Marcin Borkowski <address@hidden> writes:

> OK, so what about this?  Is there a better way (which would probably
> mean, is such function already defined)?
>
> (defun alist-clear (alist)
>   "Return ALIST with all pairs with nil value deleted."
>   (if alist

Better use when in this case.

>     (if (cdar alist)
>             (cons (car alist)
>               (alist-clear (cdr alist)))

The bad thing (shared with your plist-clear) of this, is that it's a
non-terminal recursive call, and therefore it will use O(n) stack space
with n = (length alist).  Ie. it will break for not so long alists.

See the variable max-lisp-eval-depth.

>             (alist-clear (cdr alist)))))


-- 
__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]