[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FIRST SECOND THIRD ... (don't forget REST)



I always try to avoid situations where I'd want to write obscenities like
SEVENTH ... why should it be the SEVENTH thing?  Better make it a macro so
that I can change it later!  And then (SETF (FROB X) BAR) wins totally,
while (SETF (SEVENTH X) BAR) and (SETF (CADDDR (CDDDR X)) BAR) still don't
say why you think 7 is such a magic number.  FIRST and REST are fine, they
say you are dealing with a homogenous list of items.  But even then, it's
better to write (POP X Y) rather than (SETQ Y (FIRST X)) (SETQ X (REST X)).

The point is that CAR/CDR are the low-level primitives of the language,
and concepts like FIRST, REST, SECOND, THIRD, etc. are all semantic overlays on
these basic concept, assuming left-right non-recursive character to your
data structure.  But these don't even deal well with such simple structures as
the ALIST.  Do you really want to write (FIRST (FIRST X)) to get the top tag
on the ALIST, and (REST (FIRST X)) for the CDR of the top CONS, which might
be, say, a FIXNUM?  REST is hardly apropriate there.  Even the outer FIRST
in the first one isn't quite right, since it's hardly the first element of
a sequence.

So sure, use FIRST, SECOND, THIRD, etc. when they're apropriate.  But don't
mistake them for being the underlying primitives of the language.