Re: Handling deep list recursion
milkvetch <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <87y0iq2zhk.fsf@syzygy> |
You can just use ‘named-let’ and write the function in a recursive way,
without having to worry about list length. This is the equivalent of
what you wrote:
(defun alistp (object)
(named-let recur ((obj object))
(when (proper-list-p obj)
(if (atom obj)
(eq obj nil)
(and (consp (car obj))
(recur (cdr obj)))))))
Although this doesn't return t only for valid alists; ‘consp’ returns
true for _all_ cons cells, not just (KEY . VALUE) pairs.