News for hackers. Stuff that matters.
Re:CAR and CDR by RBerenguel on Wednesday November 20, 2013 @05:09AM (#6767208)
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
Re:CAR and CDR by phoboslab on Wednesday November 20, 2013 @05:20AM (#6767234)
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

Re:CAR and CDR by RBerenguel on Wednesday November 20, 2013 @06:02AM (#6767335)
I don't mind that much unix commands, in general (with their names, not with their usage, I hate using grep and find.)

I hate chmod, too, because I can't remember exactly what permissions are what (number-wise.) My fault, not his. But I'd love it to be named "grant" and have a neater language. Like grant user/group/whatever read,write,execute (rwx are actually okayish...) filename. I know chmod is more or less like this. But I don't stand it. It's like combinatoric problems, something deep inside of me refuses to accept doing it :)

I guess you know what grep stands for, don't you? It's a "legacy" command from an early version of ed, g/re/p as in "global search" a "re"gex "p"rinting results. It could be named re (for regex, search implicit) or res (I like this.) Anyway, I use ag (the silver searcher) for text/code search, though. Less letters, easier to use (I keep forgetting if I need -r, -e and all that, ag makes it somewhat easier.)

As for mv, cp, rm, if all 2-letter acronyms were that easy to remember! Did you use extensively DOS? Most commands where far too verbose, I cringe if thinking about having to write copy to copy. Cp is just a smash with the left hand and another with the right hand and off you go. Minimise errors, 2 strokes. Actually now I wonder why in nix we have clear and not cls (or just cl)

As a matter of names... Plan9 uses nix names, and since Plan9 tried to do things "differently" almost just for the sake of it, either they didn't think about it or thought it was a bad idea.

Re:CAR and CDR by jenrzzz on Wednesday November 20, 2013 @06:12AM (#6767371)
You can use symbolic modes in chmod too if you can't remember the octal representation. For example, you could set 0755 with "u=rwx,go=rx."
Re:CAR and CDR by fit2rule on Wednesday November 20, 2013 @10:36AM (#6768588)
Meh, whats one word cloud over another? We can just say the reason for Unix is because: history, and be done with the discussion .. throw a bit of 'its probably because IBM Selectric had easy keys for | and blah' seasoning, douse a fair bit of flamage with bowls of "oh, the monte-carlo on the keypresses says that its all EMACS fault" kerosene, but then again, like I said: whats one word cloud over another? I've heard much relief, for example, from the no-more-Powershell-users who finally 'grok' bash, while (1) grep :P * ; done
Re:CAR and CDR by Peaker on Wednesday November 20, 2013 @05:47AM (#6767300)
*nix commands are optimized for minimizing keystrokes, too.

Would you like to type out 2-3x more characters per command?

Re:CAR and CDR by phoboslab on Wednesday November 20, 2013 @05:55AM (#6767321)
Yes, I wouldn't mind. That's what I'm saying. Imho it's a false assumption that you have to "minimize keystrokes". Programming languages noticed this a while ago.

The time I spent thinking "what was that command again?" is far greater than the time I would need to type a few more characters.

Re:CAR and CDR by thaumasiotes on Wednesday November 20, 2013 @06:12AM (#6767369)
> The time I spent thinking "what was that command again?" is far greater than the time I would need to type a few more characters.

For ls? rm? mv?

I use ls many times per day. Lengthening the name would be a huge loss for absolutely no gain; the odds of my forgetting what it's called are precisely zero. The more you use something, the more gain you get from a short name; unix commands are a near-perfect example of where even cryptic names (which mv, cp, rm, and ls do not qualify as) are very desirable.

Re:CAR and CDR by nknighthb on Wednesday November 20, 2013 @06:13AM (#6767376)
Commands are not APIs, and an interactive shell is not a programming language. It's an interactive user interface that some of us spend significant portions of our lives dealing with. I no more want to type an API-like "list_files" command ten billion times than I want to have it take ten mouse clicks to launch an application.
Re:CAR and CDR by MichaelGG on Wednesday November 20, 2013 @06:14AM (#6767379)
PowerShell does that - everything's a long verbose command. It helps avoid clashes in the global namespace. But it's only really usable with autocomplete. Same with Java, C#, and so on. Also, in local scope, long verbose names are far less readable. It might seem more skimmable or easy to get into a codebase with verbose names, but when you're debugging pieces of code, all the extra letters seem to clutter things up.
Re:CAR and CDR by mkesper on Wednesday November 20, 2013 @07:54AM (#6767689)
Sure, t, i, j and f are much more readable than elapsed_time, row_index, col_index and input_file. ;)
Re:CAR and CDR by RBerenguel on Wednesday November 20, 2013 @06:02AM (#6767341)
As I answered about (so I'm repeating it again :D) minimising keystrokes can also minimise typos (or generate horribly harmful ones, too, agreed)
Re:CAR and CDR by groks on Wednesday November 20, 2013 @09:40AM (#6768215)
Why did you type it's instead of it is? Is it really so much work to type one more character to justify this? :-)

The shell is a working language as much as English is. You'll spend more time using it than learning it, so get crackin'.

Re:CAR and CDR by petercooper on Wednesday November 20, 2013 @05:15AM (#6767220)
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.
Re:CAR and CDR by MichaelGG on Wednesday November 20, 2013 @06:16AM (#6767383)
What's wrong with an ordinal sort? car sorts before cdr.
Re:CAR and CDR by petercooper on Wednesday November 20, 2013 @06:47AM (#6767490)
Good point!
Re:CAR and CDR by RBerenguel on Wednesday November 20, 2013 @06:04AM (#6767350)
I just hard-wired into my brain they are car and cdr (I read it as "cadar," with both a's quite like the a in car, Spanish a for me.) In a cons list, you have the car (first) and then the cadar. Think it enough times and it sinks eventually.
Re:CAR and CDR by philwelch on Wednesday November 20, 2013 @07:01AM (#6767533)
But "cadar" is also a thing: it's the car of the cdr of the car.
Re:CAR and CDR by RBerenguel on Wednesday November 20, 2013 @07:42AM (#6767643)
I know, I'm no lisp beginner, but the pronunciation of cdr is almost like "cadar". I just "Spanishised" it.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @04:44AM (#6767127)
Still prefer first and rest. At least that has meaning outside the first use of car and cdr.
Re:CAR and CDR by agumonkey on Wednesday November 20, 2013 @05:12AM (#6767213)
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.

Re:CAR and CDR by mercurial on Wednesday November 20, 2013 @04:48AM (#6767141)
I'll take head/tail over first/rest, but first/rest is not too bad.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @04:54AM (#6767163)
I thought that for a bit until I realised tail is a bit ambiguous as it's used in the Unix space to mean the "last n" items and in some data structures as the last item pointer.
Re:CAR and CDR by mrottenkolber on Wednesday November 20, 2013 @05:02AM (#6767188)
Ironically in CL LAST does what UNIX tail does.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:03AM (#6767191)
Yeah which is where SBCL and me got into to a bad argument :)
Re:CAR and CDR by mrottenkolber on Wednesday November 20, 2013 @05:10AM (#6767209)
You probably were looking for LAST1 (e.g. (first (last ...))).

But why SBCL? LAST should behave the same on all implementations.

Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:25AM (#6767246)
That's just the variety of CL that I used.
Re:CAR and CDR by lgarron on Wednesday November 20, 2013 @05:30AM (#6767259)
I'm a fan first/rest because of Mathematica. It has four functions that all end in "st", which means I can always recall the one I need:

First, Rest, Most, Last

(Results on Range[4], respectively: 1, {2, 3, 4}, {1, 2, 3}, 4.)

Re:CAR and CDR by draegtun on Wednesday November 20, 2013 @07:32AM (#6767613)
Rebol comes with first & last but not the others.

  >> a: [1 2 3 4]
  == [1 2 3 4]

  >> first a
  == 1

  >> last a
  == 4
This is how you could add rest & most:

  >> rest: func [s] [next s] 
  >> most: func [s] [copy/part s back tail s]

  >> rest a
  == [2 3 4]

  >> most a                                  
  == [1 2 3]
Rebol unifies all this under what it calls a series - http://www.rebol.com/docs/core23/rebolcore-6.html
Re:CAR and CDR by lcedp on Wednesday November 20, 2013 @07:06PM (#6772213)
In Clojure it's almost the same: first, rest, butlast, last
Re:CAR and CDR by mrottenkolber on Wednesday November 20, 2013 @04:54AM (#6767162)
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.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @04:59AM (#6767179)
Yes but every structure that a cons represents can be expressed in terms of first and rest. That includes tables, singly linked lists, doubly linked lists, binary trees from experience.

Car and Cdr are arbitrary and legacy terms.

Re:CAR and CDR by mrottenkolber on Wednesday November 20, 2013 @05:07AM (#6767199)
Arbitrary and legacy, sure, but they do serve their purpose by communicating different expectations when using a single operator. CDR? result can be anything. REST? author probably thinks the result will always be a LIST. I can think of other examples using SETF but I think I made my point clear.
Re:CAR and CDR by yati on Wednesday November 20, 2013 @05:41AM (#6767285)
Same here, but cons cells can be used to model things other than lists, where semantically first and rest don't make sense.
Re:CAR and CDR by thaumasiotes on Wednesday November 20, 2013 @06:17AM (#6767389)
I once wrote an in-place quicksort in common lisp where I kept pointers to locations of interest in the list as halves of a cons cell. Was kind of fun coming across it later and figuring out what it did. That cons cell made no semantic sense as a linked list; it was just a pair of pointers.
Re:CAR and CDR by outworlder on Wednesday November 20, 2013 @07:35AM (#6767622)
They are better, until you try to compose them :)
Re:CAR and CDR by xmonkee on Wednesday November 20, 2013 @04:59AM (#6767180)
but saying "cudder" is so much more fun
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:02AM (#6767190)
Yes but macros like caaaaaar and caaadr aren't :)

I'd rather salt my eyeballs.

Re:CAR and CDR by l0gicpath on Wednesday November 20, 2013 @05:08AM (#6767203)
Such a horror to see this in a large code base. s-expressions can get mentally taxing as it is, but then the abuse of continued acceptance is sad.
Re:CAR and CDR by elrzn on Wednesday November 20, 2013 @07:06AM (#6767554)
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

Re:CAR and CDR by draegtun on Wednesday November 20, 2013 @11:00AM (#6768763)
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
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @07:34AM (#6767619)
Noooooooooooooooooooooooooooooooooooooooo.

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

Re:CAR and CDR by joeygibson on Wednesday November 20, 2013 @06:43AM (#6767475)
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.
Re:CAR and CDR by kang on Wednesday November 20, 2013 @05:20AM (#6767235)
quote used to mark data as opposed to code can be tricky while using CDR & CAR : http://stackoverflow.com/questions/18697105/cdadr-on-nested-...
Re:CAR and CDR by Syssiphus on Wednesday November 20, 2013 @07:11AM (#6767564)
:* <3 u LISP
Re:CAR and CDR by derleth on Wednesday November 20, 2013 @06:12AM (#6767370)
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.