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

CAR and CDR



My first sentence in my last note on rereading (and HIC flaming) is bullshit.
There ARE indeed cases where the SEVENTH element is EXACTLY what you want to
say.  I do contradict myself at the end, even.  And certainly FIRST and REST
are very often exactly the right thing.  I apologize for the flame and smoke.

However, as KMP points out, it's often better to use destructuring to pick
out the components than doing (FOURTH X) ... (FIFTH X) .... and more efficent
besides.  With a destructuring LET or a DESETQ you give NAMES for these
components; they usually have meaning beyond merely being the 7th element.
You also give a graphic representation of the the item is to look like.

Besides, the only unmnemonic part about CAR and CDR is the A and D, which
are nothing more than arbitrary names...I can't quite think of how you're
going to explain LISP without their being able to understand "Contents";
Register is easy to explain...a place to store something!  So your
explanation can dwell on CAR being an operation to extract one of the
contents of a CONS.  You can tell how the A and D got in there as an amusing
and educational story of how names in CS, once chosen, tend to stick.  And how
they should choose well the names they use for making sense, as if the names
they choose might outlast them!  That's enough for them to remember CAR and
CDR.

By all means, they should use FIRST, REST, (and when aprpriate, SECOND, etc.)
in their code when that's what they mean.  But I think you should also teach
them that such things are constructed out of these low level primitives, and
that this building of high-level operations out of low-level is one of the more
important aspects of LISP (and indeed, all good programming).