4 ms·
> Whew. This is why a twenty-first century language, like Racket, uses archaic, un-helpful fifty year old terms. While Matthew Flatt and team could have changed
by adamddev1 5y ago
> Whew. This is why a twenty-first century language, like Racket, uses archaic, un-helpful fifty year old terms. While Matthew Flatt and team could have changed these terms, they were keeping with a long tradition.
To be fair, Racket and LISP do have the procedures `first` and `last` for accessing lists, but also keeps `car` and `cdr` for accessing either pairs or lists. Clojure did away with `car` and `cdr`, but it also did away with the ability to make plain pairs from `cons`.
Racket:
> (first (cons 1 '())) # w list
1
> (car (cons 1 '())) # w list
1
> (first (cons 1 2) # w pair
ERROR
> (car (cons 1 2)) # w pair
1
Clojure:
> (first (cons 1 '())) # w list
1
> (cons 1 2) # pairs not allowed
ERROR
https://docs.racket-lang.org/reference/pairs.html https://docs.racket-lang.org/reference/pairs.html
- lispm 5y agoCommon Lisp has FIRST, SECOND, ..., TENTH and REST. http://www.lispworks.com/documentation/HyperSpec/Body/f_firstc.htm#first http://www.lispworks.com/documentation/HyperSpec/Body/f_firs...
- adamddev1 5y agoThanks, I didn't know that but edited my comment accordingly.
- nomorecommas 5y agoSure does. In my own code I prefer `NTH` for anything beyond the cadr. Or just use arrays for random access.
- betterunix2 5y agoNote that "second" will not work as intended if you just have a pair; it access the second element of a list. I rarely find any use for anything beyond first, second, and rest; if I need to access nth elements I will likely switch to a different data structure.
- bsder 5y ago> Clojure did away with `car` and `cdr`, but it also did away with the ability to make plain pairs from `cons`. And it also means that more things than lists can be accessed as sequences using iterators. The whole "Have to recurse the entire chain to figure out if something is terminated with nil/() and therefore a list" is part of the reason why everybody bangs on about tail recursion instead of just writing an imperative loop.
- kazinator 5y agoRacket doesn't keep any "tradition"; the traditional, mutable conses are found under different naming here: https://docs.racket-lang.org/reference/mpairs.html https://docs.racket-lang.org/reference/mpairs.html Moreover, "a mutable pair is not a pair; they are completely separate datatypes". So, I think, you can't make a piece of syntax out of these and pass them to the evaluator or compiler. So, this doesn't even give a tip of the hat to the tradition of Barbara Liskov's substitution principle where you'd expec that a "mutable pair" is-a kind-of "pair", and so on.