4 ms·
I'm surprised cadr, caddr, cddr, etc. were not mentioned when comparing car/cdr with first/rest. See http://www.franz.com/support/documentation/8.2/ansicl/dict
by techiferous 16y ago
I'm surprised cadr, caddr, cddr, etc. were not mentioned when comparing car/cdr with first/rest.
See http://www.franz.com/support/documentation/8.2/ansicl/dictentr/carcdrca.htm http://www.franz.com/support/documentation/8.2/ansicl/dicten...
- masklinn 16y agoIndeed, so was I: the cºr indirections strike me as a very good reason to not switch to `first` and `rest` (or `head` and `tail`) in Lisp: they provide an unambiguous and readable way to quickly traverse multiple levels of datastructures (as long as they're not abused too much) which is not as easy to generally replicate using more meaningful names.
- kaylarose 16y agoMaybe it's just my mental model, or being new to the language. But while going through SICP - 'cdadadr', 'cddaadr', etc. never really "clicked" in my mind. Really anything past 3 levels (cadar, cddar, etc.) always slowed down reading code, like hitting a speed bump. I would have to stop and really try to grok what list item it was referring to. Not saying that that is a bad thing, just an observation. Is there a common way of thinking that makes it easier to comprehend, or is it just something that comes with experience?
- techiferous 16y agoI worked with Scheme (a type of Lisp) professionally for over a year and even after heavy usage there were still lots of syntax "speed bumps" like this that slowed me down. I really enjoyed a lot of the concepts of Scheme but the syntax was a bummer and I'm so glad I'm not programming with it anymore. :)
- kaylarose 16y agoYep Scheme was what I was using with SICP. I've heard of Common Lisp in passing, does it have a more friendly syntax?
- deleted 16y ago[deleted]
- mschaef 16y agoThere's a lot more capability built into the Common Lisp specification than there is in R5RS (dunno much about R6RS), but the syntax is very similar. More than the syntax, Common Lisp is probably best distinguished by the fact it gives you a different set of techniques for partitioning names. Scheme has hygenic macros and a namespace that's unified between functions and values. Common Lisp has non-hygenic macros, but separate namespaces for values and functions, as well as a package construct that lets you use the same spelling of a symbol for different symbols. Common Lisp also has more 'built in' kinds of control flow structures, etc., but it doesn't have anything quite like call/cc.
- mschaef 16y ago> Maybe it's just my mental model, or being new to the language. But while going through SICP - 'cdadadr', 'cddaadr', etc. never really "clicked" in my mind. Really anything past 3 levels (cadar, cddar, etc.) always slowed down reading code, like hitting a speed bump I've used Lisp for a while, and where I tend to wind up on these composite forms is that I use a few of the simpler composites, but tend to switch to either destructuring-bind or some other data type if it gets too complex. (Practically speaking, that means anything much beyond 'car', 'cdr', and 'cadr' gets refactored.)
- mschaef 16y agoThey should have been, since that's one of the best 'current benefits' of the names. (Were I writing the post now, I'd include that argument too.)