top | item 6767031

CAR and CDR

40 points| sabalaba | 12 years ago |en.wikipedia.org | reply

46 comments

order
[+] RBerenguel|12 years ago|reply
I always forgot which was which until I actually forced me to use them for a while (and "while" was too long). The only cool thing of the names is that you can get a cryptic sticker "My other car is a cdr" that no-one will understand but will make you jiggle each morning
[+] phoboslab|12 years ago|reply
I feel the same way about many *nix commands. A while ago I thought it was neat to have TLAs[1] for everything, but now I just think it's bad "API" design.

Why is it ls instead of list? chmod instead of permissions? grep instead of search? mv, cp, rm instead of move, copy, remove? Is it really so much work to type a few more characters to justify this?

Programming langue APIs (or rather their libraries) have come a long way since the C days in that regard, but OS wise we're still stuck with these cryptic names.

[1] http://en.wikipedia.org/wiki/Three-letter_acronym

[+] petercooper|12 years ago|reply
Mine is "car" and "CarDriveR" (implying first comes the car, then its driver). "CorriDoR" is another one which implies the extra length a bit better.
[+] csmuk|12 years ago|reply
Still prefer first and rest. At least that has meaning outside the first use of car and cdr.
[+] agumonkey|12 years ago|reply
I can't disagree with that, but after learning clojure I realized that I interned `car` and `cdr` as symbols of which I like :

  - the symmetry: 'c[ad]r'
  - thus same size
  - small size (3)
and ended up being annoyed by `first` and `rest`. I see them as APL-like characters now.

ps: based on that, head/tail, hd/tl, fst/snd (seen in ml dialects) are also good candidates.

[+] mercurial|12 years ago|reply
I'll take head/tail over first/rest, but first/rest is not too bad.
[+] mrottenkolber|12 years ago|reply
It has nothing to do with preference. FIRST and REST are to be used when working on a LIST, CAR and CDR when working on CONS cells.
[+] yati|12 years ago|reply
Same here, but cons cells can be used to model things other than lists, where semantically first and rest don't make sense.
[+] outworlder|12 years ago|reply
They are better, until you try to compose them :)
[+] xmonkee|12 years ago|reply
but saying "cudder" is so much more fun
[+] elrzn|12 years ago|reply
It's a pity they're not standard in many other languages. I'm not a fan of having to type first/rest or playing around with syntax soup and I really miss caddadadaddaaaaaring around.

sub car { $_[0] } sub cdr { shift; @_ } # every utils module ever

[+] draegtun|12 years ago|reply
Plonk that into an autobox module (like perl5i and/or autobox::Core) and enjoying even more caddadadaddaaaaaring around!

For eg:

  use perl5i::2;

  sub autobox::Core::ARRAY::car { $_[0]->[0] }

  sub autobox::Core::ARRAY::cdr {
      my $last = $#{$_[0]};
      wantarray ? @{$_[0]}[1 .. $last] : [@{$_[0]}[1 .. $last]];
  }
then...

  my @a = 1..4;

  @a->car;             # 1
  @a->cdr->cdr->car;   # 3
  @a->cdr;             # 2, 3, 4

  my @x = @a->cdr;
  @x->cdr;             # 3, 4
Some refs: https://metacpan.org/pod/perl5i | https://metacpan.org/pod/autobox::Core
[+] csmuk|12 years ago|reply
Noooooooooooooooooooooooooooooooooooooooo.

Perl can be written ugly enough without introducing car and cdr to it!

[+] joeygibson|12 years ago|reply
I first learned Lisp so long ago that car and cdr are still ingrained in my head. first and last feel somehow wrong, to me.
[+] derleth|12 years ago|reply
I like them because they don't guide thought: They're abstract names for abstract concepts. They don't impose any interpretation on the ideas, they simply present them for what they are. Having to break down a less-useful conceptual model is even more difficult than building a more-useful one.