car(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… car(3scm) β€” the one where we grab the head and the tail

okay so this is car(3scm) from the Scheme Programmer's Manual, and bestie, it's literally the most iconic page in the whole manual. we're talking head-of-the-list, tail-of-the-list, the absolute fundamentals. no cap. πŸŽ€


✨ NAME ✨

car, cdr β€” the car or cdr field of a pair (head and tail). that's it. that's the whole vibe. πŸ¦‹


πŸ“š LIBRARY πŸ“š

like, import it from whichever flavour of Scheme you're living in:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme base))              ;R7RS

🫢 SYNOPSIS 🫢

(car pair)
(cdr pair)

πŸ’– DESCRIPTION πŸ’–

So. Both of these return the contents of the car or cdr field of a pair. Simple, clean, main character energy. ✨

They also work on lists, because in Scheme a list is literally a linked list of pairs (iykyk). The car procedure returns the head of a list. The cdr procedure returns the tail of a list. Obsessed with the symmetry, honestly. πŸ“


🌸 RETURN VALUES 🌸

Returns the contents of the car or cdr field of pair. slay.


πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types β€” pay attention bestie, this part matters:

  • &assertion (R6RS) β€” The argument is not a pair.
  • &assertion (R6RS) β€” The wrong number of arguments was passed.
  • R7RS β€” The situations described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.
πŸ’€ "fail catastrophically" is doing a LOT of work in that sentence and honestly it's giving horror movie. R7RS really said do whatever. just know the rules are loose here, fr fr.

πŸ‘‘ STANDARDS πŸ‘‘

R4RS, IEEE Scheme, R5RS, R6RS, R7RS β€” certified across the eras, we love a legend that never goes out of style. 🌈


πŸ”₯ EXAMPLES πŸ”₯

(car '(a b c))      => a
(car '((a) b c d))  => (a)
(car '(1 . 2))      => 1
(car '())           => &assertion exception

(cdr '((a) b c d))  => (b c d)
(cdr '(1 . 2))      => 2
(cdr '())           => &assertion exception

note how (car '()) and (cdr '()) both go straight to &assertion exception β€” the empty list said "not today" 😭


πŸ¦‹ SEE ALSO πŸ¦‹


⭐ HISTORY ⭐

Present in MIT AI Memo No. 1 (September 1958). like... 1958?? the ancestors really invented this and it's STILL eating. genuinely iconic. πŸ‘‘


🧚 AUTHORS 🧚

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


πŸ’œ okay bye bestie, that's the page β€” dated 2020-04-18, stamped car(3scm), and that's on periodt. go call car on something and feel powerful. πŸ’…βœ¨

πŸ“¦ where this page comes from