News for hackers. Stuff that matters.
Re:The Background for CAR and CDR by adamddev1 on Monday December 27, 2021 @07:22AM (#29701907)
> 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
Re:The Background for CAR and CDR by lispm on Monday December 27, 2021 @07:31AM (#29701960)
Common Lisp has FIRST, SECOND, ..., TENTH and REST.

http://www.lispworks.com/documentation/HyperSpec/Body/f_firs...

Re:The Background for CAR and CDR by nomorecommas on Monday December 27, 2021 @08:29AM (#29702327)
Sure does. In my own code I prefer `NTH` for anything beyond the cadr. Or just use arrays for random access.
Re:The Background for CAR and CDR by betterunix2 on Monday December 27, 2021 @10:17AM (#29703120)
Note 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.
Re:The Background for CAR and CDR by adamddev1 on Monday December 27, 2021 @07:48AM (#29702071)
Thanks, I didn't know that but edited my comment accordingly.
Re:The Background for CAR and CDR by kazinator on Monday December 27, 2021 @07:48PM (#29708917)
Racket doesn't keep any "tradition"; the traditional, mutable conses are found under different naming here:

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.

Re:The Background for CAR and CDR by bsder on Monday December 27, 2021 @05:09PM (#29707414)
> 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.