Comment by kazinator
8 years ago
> The 90% case here is "second", "third", etc.
Unfortunately, those cases exhibit poor style if they are mixed with cddr. For instance, I would never write this:
(when (and (consp (cdr x)) (consp (cddr x)))
(do-something (third x)) ;; ouch!
)
If we checked that cddr is a cons, we then want to access caddr (its car) or cdddr (its cdr).
Those first, second, rest and whatnot are really geared toward when the structure is a (proper!) list. If it really is just a proper list and we just want to be sure it has a third element, it would be more consistent to just do
(when (>= (length x) 3)
(do-something (third x))
Basically stick to one way or the other.
No comments yet
Contribute on Hacker News ↗