Arc Forumnew | comments | leaders | submitlogin
1 point by zck 5333 days ago | link | parent

Regarding car and cdr vs first and rest, how would you get the second element? What we have now gives us (cadr lst). Your suggestion gives us (first (rest lst)) or (first:rest lst). I guess you could argue that you could shorten them to fst and rst and compose them as frst, but that looks like first to a quick glance. In the end (I believe I'm reiterating one of pg's arguments here), all names are somewhat arbitrary, and it's ok to have names that don't relate to what they're doing if you use them enough. They become meaningful through repetition. There's nothing inherent about + that makes it mean "add" -- we've all seen it so often that we instinctively know it does.


3 points by eds 5333 days ago | link

You could always go by way of Clojure:

  car -> first
  cdr -> next
  caar -> ffirst
  cadr -> fnext
  cdar -> nfirst
  cddr -> nnext
So you really can compose the names. They're still less concise, but only by a couple of characters. If you really wanted to save those characters, use fst/rst (and ffst, frst, etc).

EDIT: I failed to completely read your post; it seems you already mentioned ffst etc. Don't know that my comment adds much to the debate.

-----

1 point by zck 5333 days ago | link

Actually, those were new to me -- I was trying to use fst and rst, and failing at it. While the Clojure way works better than my example, there's something about it that I don't like. Maybe it's simply that it's new -- if that was the original way, I'd react similarly to introducing car and cdr.

-----

2 points by thaddeus 5333 days ago | link

How about this ?....

    (= x (list "One" "Two" "Three" "Four" "Five" "Six"))

    (def first (xl)
      (car xl)) 

    (def next (xl (o n 1))
      (withs (n (+ n 1)
              nxl (cut xl 1 n))
       (if (single nxl)
           (car nxl)
           nxl)))

    (def rest (xl)
      (cdr xl))
 
So ...

    arc> (first x)
    "One"
    arc> (next x)
    "Two"
    arc> (next x 3) ; the next three
    ("Two" "Three" "Four")
    arc> (rest x)
    ("Two" "Three" "Four" "Five" "Six")
    arc> (next:rest x)
    "Three"
    arc> (rest:next x 3) ; the rest of the next 3
    ("Three" "Four")
    arc> (last:next x 3) ; the last of the next 3
    "Four"
    arc> (first:next x 3) ; the first of the next 3
    "Two"
That's six or so functions replaced by 3, that look like english and make sense.

-----

1 point by thaddeus 5333 days ago | link

I had thought "next"...

    first = car
    last = last
    rest = cdr 
    next = cadr
    next:+1 
    next:+2 
    ....
Comparing "+"/"add" to "car"/"first" is not the same thing.

"+" does mean "add" to the majority of people on earth - as its common knowledge, and thus it's intiutive. Car means "something one drives" to almost everyone.

> "all names are somewhat arbitrary, and it's ok to have names that don't relate to what they're doing if you use them enough"

Just because one can learn something faulty and get used to it doesn't mean one should accept it's faults and decide to live with it. One should strive to make it better. If this were not true - arc wouldn't exist. So why not change it?

-----

4 points by palsecam 5328 days ago | link

> "+" does mean "add" to the majority of people on earth - as its common knowledge, and thus it's intiutive. Car means "something one drives" to almost everyone.

1. From the Arc FAQ (http://paulgraham.com/arcfaq.html):

> Why did you keep car and cdr?

Because we couldn't think of any better alternatives. It would have been misleading to use first and rest or head and tail, because conses are fundamentally pairs; lists are one thing you can build with them, but not the only thing.

There's no conventional name in English for the first and second halves of a pair. If you have to make up names, car and cdr are pretty good choices, because they're short and the same length and naturally composable (e.g. cadr).

Example. I played a little the other day to implement surreal numbers (http://en.wikipedia.org/wiki/Surreal_number) in Lisp, using conses.

Basically, surreal numbers are a pair of two (surreal) numbers sets, the left one, and the right one.

0 is (() . ()), (cons () ()), where () is the empty set.

1 is (() . <surreal 0: (() . ())>)

-1 is (<surreal 0> . ())

It doesn't make sense to get the right set by saying (rest <surreal 0>), because it's just not the "rest", it's just the... cdr, i.e: the second halve of the 'cons. I mean conceptually, it's not the "rest".

2. Car means "something one drives" to almost everyone. No, no, NO. Ask, for instance, the 1+ billion Chinese people if "car" means anything to them. Just stop the fucking English-centrism. Will English be the proeminient language in 100 years? Is programming reserved to English-native-speakers? Is it good to mimic human languages in programming languages (hint: Algol VS C syntax)?

I love car/cdr because they don't mean anything.

Well actually, yes, they mean/meant something: content of {address|decrement} registry. But, in my view, they have just turn into arbitrary-chosen names for basic operations, like "+" is the arbitrary name of the "addition op" in our current arithmetic. You just learn that +/car means "this basic op", it becomes common knowledge, and you're done. I don't know, it's not even a name at this point, just the representation symbol.

I love APL (http://en.wikipedia.org/wiki/APL_(programming_language)) because it uses just symbols for ops. I love Perl's $_ / $| / $\ / etc. special vars because they don't mean anything by themselves, etc. I don't know, it just makes programmers from any country equals when it comes to speak to a computer. I love maths because nearly all the maths stuff use arbitrary-chosen "names", making people equals when it comes to speak to the Universe.

-----

2 points by thaddeus 5328 days ago | link

1. So is "last" not a pair too ? [edit] I see last does mean the last even when a pair. Where as rest may not. I'll check this out. In the end it just may be worth while to include rest and next as extra functions for the sake of language adoption? At an abstract level "rest" and "next" do accomplish what most expect it should.

>"No, no, NO. Ask, for instance, the 1+ billion Chinese people if "car" means anything to them. Just stop the fucking English-centrism."

I am willing to bet if you asked that question to every person on earth "what is car?" that statistically, the answer would represent my statement, even if by merit that some languages do not have a meaning for "car" and English, in my opinion, is more widely adopted. I could be wrong, but I don't feel bad about making that statement.

[Edited - deleted some of my own BS comments :) - thank you pg for having edit time]

Still- Maybe I should have written it this way: "Car does not mean first to almost everyone"

>"Will English be the proeminient language in 100 years?"

Not sure. I think the world we be a much better place if the average world citizen spoke multiple languages. And you never know maybe in doing so new languages could emerge and maybe there will be a "most powerful language" yet maybe it will not be widely adopted, or maybe it will.

We shall see :) (Edit - Opps - I just realized we will not)

Also I believe everyone is overlooking one point. Scheme is already more powerful, yet not widely adopted. I don't believe pg's goal in building arc is to make a scheme even more powerful. I'd like to think that pg acknowledges that language adoption should be an equally important factor to arcs' potential success.

-----

4 points by palsecam 5327 days ago | link

About 'last. Conses are a powerful, general data type. One way you could use them is to build another little-less-general data type, a subset of them, a "list", where (list 'a 'b 'c) is (cons 'a (cons 'b (cons 'c nil))).

Then you define some functions to operate (exclusively) on this new "data type", and 'last is one of them. Exclusively: (last (cons 'a 'b)) doesn't work, because it'd have no meaning to use 'last here. '(a . b) is not a list, just a cons.

Similarly, one way you could use lists is to build a-little-less-general abstraction, association lists. Then you define 'alref/etc. to use with this new data type. But (alref (list 'a 'b 'c) 'a) doesn't work, since it has no meaning in this context.

But 'car/'cdr, they operate on raw conses, not only on lists. And I said before, IMHO, 'rest is not good, because you're assuming by using this name that it is an operator for lists only. Yes, (rest '(a . b)) would work, but its meaning is crappy here (IMHO).

But you're making an interesting point. Maybe 'rest/'first should be also included, as synonyms for 'cdr/'car because actually people almost always use 'car/'cdr when working with lists, and in list context, their meaning may be easier to understand. But this is another debate.

---

About the meaning of 'car. Sure, if you're programming in one of the current dialects of Lisp, you have some basic notions of English, even if you're Chinese. Yet, when reading some Lisp code, if I see 'car I just know it means "first halve of the pair". I mean, before you pointed out that "car" means "a vehicle" most of the time, I didn't ever think about this (valid) point when reading/writing Lisp code. That's why I don't see it as a problem.

I don't know, I suppose it's because the context is important. When I see 'map in a Lisp file, I don't think about a (geographical) map. When I see 'cons I know it's not as in "pros & cons". When I see 'table, I know it's not about a dining table. When I type `cd' in my shell, I know it means "change directory" and not "compact disc", etc.

Yes, if you ask a random guy in the street what "car" means he'll answer you "a vehicle" and not "the first halve of the pair". But it's the same problem if you ask it what "cd" or "table" means. There are ton of issues like this, even in natural languages. For instance, homonyms: a tire is both a car wheel and the feeling of fatigue.

---

About language adoption. It seems pg knows it is important: So whether or not a language has to be good to be popular, I think a language has to be popular to be good. And it has to stay popular to stay good. (http://paulgraham.com/popular.html)

OTOH, remember Arc is made for "hackers" and to be adopted by "hackers" (at least at first). And there is the "100 years" idea (i.e: no rush in adoption may not be a problem). So maybe pg's idea of "language adoption" is not the same than yours ;-)

---

> (Edit - Opps - I just realized we will not)

Funny yet true one :-)

I always felt a little uncomfortable about the "100 years" idea. I keep saying to myself it's just a catch phrase for a decent goal, trying to design something timeless. But still, it also reminds me of "I intend to set up a thousand-year Reich and anyone who supports me in this battle is a fellow-fighter for a unique spiritual — I would say divine — creation". You know, the fooliness to not want to live in the current, real, impure world.

-----

1 point by thaddeus 5327 days ago | link

> "I don't know, I suppose it's because the context is important. When I see 'map in a Lisp file, I don't think about a (geographical) map. When I see 'cons I know it's not as in "pros & cons". When I see 'table, I know it's not about a dining table. When I type `cd' in my shell, I know it means "change directory" and not "compact disc", etc"

Absolutely and it's "because the context is important" that I made the suggestion. I don't really care that it's called "car". I'm just suggesting that IF you're going to have a function called "last" why wouldn't you create "first", as the user will intuitively try to use it given that last exists.

:)

-----

1 point by conanite 5323 days ago | link

You make a powerful point about cons cells being a more fundamental type than lists. I think if we really wanted english language words to describe the parts of a cons, "left" and "right" would be appropriate for what a cons is in isolation, but would unfortunately be meaningful only if you're using conses to represent binary trees. The beauty of a cons is that it's the smallest possible structure out of which one can build arbitrarily larger composites. And I'm not sure how valuable metaphors from the physical world are when contemplating abstractions - a cons is another degree removed from everyday reality than windows, buttons, dialogs, tabs, and menus are.

-----