2 ms·
There's nothing you can call them that will make any more sense than CAR and CDR. You can call them BOB and DOUG, LEFT and RIGHT, UP and DOWN, CAKE and DAFFODIL
by agentultra 12y ago
There's nothing you can call them that will make any more sense than CAR and CDR. You can call them BOB and DOUG, LEFT and RIGHT, UP and DOWN, CAKE and DAFFODIL. It wouldn't matter. They're still just symbols to a function that deferences the associated pointer in a cons cell. The powers that be chose CAR and CDR and they're about as good as any.
The bonus discovery that the (car (cdr some-cons-cell)) could be shortened to CADR via a macro was just icing on the cake. Now we have a macro that can access any part of an abstract tree. Nice.
There's nothing intuitive about programming. There's no analogy you can apply to CAR and CDR or even CONS which will suddenly make sense to your primitive mind. You can't pick up a cons cell in your handle, fiddle with it, and throw it back at the computer. There's no analog in nature which resembles it. It's an ephemeral thing that only exists inside a machine because an idea someone had made it so. So stop looking.
If that's the biggest hurdle to learning Lisp I'd be surprised if someone could be taught to program in any other language. Try teaching C declaration syntax to someone.
char *(*c[10])(int **p);
I can explain a cons cell in five minutes tell you that there are two functions for accessing its sub-parts and we can move on.
... to red-black trees, skip lists, linked lists, circular buffers, trieps, whatever.
Update: I don't mean to say I'd be surprised if someone could be taught to program in any other language in any sort of glib or pejorative sense. Of course one can learn to program without hearing about a cons cell. What I mean by that is it takes some willingness to accept abstract concepts and turn them into symbols in order to learn how to manipulate them.
- dragonwriter 12y ago> There's nothing intuitive about programming. If that was true, than naming constructs in programming languages wouldn't matter at all. > If that's the biggest hurdle to learning Lisp Its not, its just one of many small hurdles that keep Lisp as a fairly niche language, despite its strengths when viewed from a 30,000 foot level. > Try teaching C declaration syntax to someone. C-family languages declaration syntax is a major factor in the popularity of dynamically typed languages (newer statically typed languages that are starting to take back some ground mostly reduce both the clutter of that syntax and the need for declarations at all.) So, other than illustrating the a similar (but larger) problem to the car/cdr problem, I'm not sure what the relevance is.
- agentultra 12y ago> If that was true, than naming constructs in programming languages wouldn't matter at all. http://dictionary.reference.com/browse/intuitive http://dictionary.reference.com/browse/intuitive I think we're diverging off the track here. Naming is important. Programming has borrowed quite a lot from various places to name the often weird, alien "things" we work with. But a rose by any other name is still a rose. There is no name for which there exists an analog in nature that we can apply to CAR and CDR. You can't think about them intuitively. As demonstrated elsewhere calling them FIRST and REST is a mistake. FIRST, SECOND, THIRD and so one are just English words for for CAR, CADR, CADAR, and so on. So it's best not to get stuck in the "intuitive" trap. CAR and CDR have stuck around because people have argued about it endlessly for 40 years and haven't come up with a better name. They took on abstract symbols and the people writing Common Lisp code kept shipping systems. > Its not, its just one of many small hurdles that keep Lisp as a fairly niche language I don't think that's the reason for it's lack of market share. That has more to do with corporate politics and business. Read up on the history of Symbolics. tldr; there were once only commercial implementations of Common Lisp that cost far too much and delivered little. Because money. So a couple generations of programmers didn't get exposed to it as their first language. > C-family languages declaration syntax is a major factor in the popularity of dynamically typed languages Is that so? Why then are their interpreters and virtual machines written in C or some other language? PyPy is making an effort but even then... lots of C. Most implementations I've seen of Common Lisp are written in Common Lisp. Odd. CAR/CDR isn't a problem. I've explained it five times in various posts on this thread. There's even a link to the HyperSpec (the HTML form of the ANSI specification). It's quite simple. The real problem is that Common Lisp isn't the first language for most "newcomers." So they come packed with notions and biases that they forget to leave at the door. If C is your first language pointers aren't a big deal and you learn to read the declaration syntax. You know it's not great and that it's difficult to pick up but once you get it you move on. In a similar fashion when you pick up Lisp you figure out CAR and CDR. Changing the names of CAR and CDR isn't going to make Lisp any more appealing to newcomers. You just have to learn what they are and move on.
- lispm 12y ago>tldr; there were once only commercial implementations of Common Lisp that cost far too much and delivered little. Because money. Which is complete bullshit.