3 ms·
Why keep the existing primitives? Things like car and cdr were implementation accidents.
by bayareaguy 19y ago
Why keep the existing primitives? Things like car and cdr were implementation accidents.
- dfranke 19y agoFrom the FAQ: 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).
- corentin 19y agoThere's no conventional name in English for the WHAT and WHAT of a pair? :)
- andrewl 19y agoWell, you need terms that apply to the first and second halves of a pair as well as the first element in a list and all the rest of the list. First and second work for lists of two items, but they don't feel right to me for longer lists. Also, they aren't the same length, and that would bother me. I'd prefer left and rite. Or alpha and omega. Or mom and pop. Then you can compose them into mop. Or maybe I'd better leave it to Paul, as I obviously can't be trusted with this kind of thing.
- lisper 19y agoI suggest FST and RST. These are composable, e.g. FFRRST == CAADDR.
- bayareaguy 19y agoI guess I wasn't really thinking about why choose those names. If it was just that you could have whatever you like - I like (hd x) and (tl x) but that's me. Or even (0 x) and (1: x) could work. A rose is a rose and all that. What I was really thinking about were things like why have pairs as a primitive and why enshrine the idea of lists as pairs linked up in a certain way? From ac.scm, it looks like the current set of primitives are: (define (ar-type x) (cond ((ar-tagged? x) (vector-ref x 1)) ((pair? x) 'cons) ((symbol? x) 'sym) ((null? x) 'sym) ((procedure? x) 'fn) ((char? x) 'char) ((string? x) 'string) ((integer? x) 'int) ((number? x) 'num) ; unsure about this ((hash-table? x) 'table) ((output-port? x) 'output) ((input-port? x) 'input) ((tcp-listener? x) 'socket) ((exn? x) 'exception) (#t (err "Type: unknown type" x)))) So why that set? Why have chars and strings and symbols? Why have integers and numbers?