Arc Forumnew | comments | leaders | submitlogin
Possible alternatives to car/cdr
2 points by anarcer 5695 days ago | 4 comments
I apologize in case the idea should have already been suggested and rejected: hp, tp or fp for car and rp for cdr.

They are short and same length: hp = head element of pair or tp = top element of pair or fp = first element of pair

rp = rest of pair

They are also naturally composable: hrp = head rest of pair hrhhp = head rest head head of pair

Aren't they in Unix-like tradition and consistent with the new Arc sintax?



1 point by rkts 5694 days ago | link

They're short, but they don't look nice.

I find code easier to read when the names are easily spoken aloud. In the language I'm working on (nothing serious) all the common names are either English words or things that look like English words. I also favor short words over long words and Germanic words over Latin words, and I avoid abbreviations as much as possible (except in local variables, which are usually single letters). It helps me a lot.

As to car/cdr specifically, though, I think the best option is pattern matching.

-----

2 points by krg 5689 days ago | link

Well, cdr can't really be spoken aloud unless you make up a way to pronounce it (which of course people do). And you could do the same for hp, rp, and the rest... adding an "o" sound gives some nice words, like hop, top, and fop. Kind of a Dr. Suess feel. :)

-----

1 point by anarcer 5694 days ago | link

Yes, but IMHO they are omogeneous with the other abbrevs in Arc sintax and are also conceptually clearer than car/cdr (that refer to old registers of an old pc): for example, hp (head of pair), tp (tail of pair) and hthtp (head tail head tail of pair) may help conceptual visualization...

-----

2 points by anarcer 5687 days ago | link

Can anybody tell me where I could find discussion about this topic?

BTW, just to complete my previous example:

!hp for set-car !tp for set-cdr ?hp and similar for predicates...

-----