caaar(3scm)
π caaar(3scm) β additional compositions of car and cdr
okay so bestie, buckle up π this is caaar(3scm) from the Scheme Programmer's Manual, and it's genuinely the deep-lore cousin of caar(3scm). Same energy, way more letters. π
π LIBRARY π
import these depending on which flavour of Scheme you're living in, no cap:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme cxr)) ;R7RS
β¨ SYNOPSIS β¨
here's the whole squad, all twenty-four of them (the page lists (caaar pair) twice, and honestly? she said it twice because she's iconic. I'm just copying her π
):
(caaar pair)
(caaar pair)
(caadr pair)
(cadar pair)
(caddr pair)
(cdaar pair)
(cdadr pair)
(cddar pair)
(cdddr pair)
(caaaar pair)
(caaadr pair)
(caadar pair)
(caaddr pair)
(cadaar pair)
(cadadr pair)
(caddar pair)
(cadddr pair)
(cdaaar pair)
(cdaadr pair)
(cdadar pair)
(cdaddr pair)
(cddaar pair)
(cddadr pair)
(cdddar pair)
(cddddr pair)
π¦ DESCRIPTION π¦
so these twenty-four procedures are just further compositions of car and cdr, built on the exact same principles as caar(3scm). like, same recipe, more layers. π§
for example, caddr could be defined by:
(define caddr (lambda (x) (car (cdr (cdr x))))).
and honestly that's the whole vibe: arbitrary compositions up to four deep are provided. four. that's the max depth, bestie. πΈ
π RETURN VALUES π
it returns the contents of the car or cdr field of the pair which is the next to last pair through the chain of pairs. π«Ά yes, the next to last one β she's not the last, she's the one right before it, main character energy.
π₯ EXAMPLES π₯
real ones, look how she eats:
(cadar '(((a . b) . (c . d)) ((1 . 2) . (3 . 4)))) => c
(cddddr '(1 2 3 4 5 6)) => (5 6)
π APPLICATION USAGE π
ngl, these compositions are increasingly harder to read and reason about. π like not to be dramatic but your future self WILL be squinting at cddadr at 2am wondering what year it is.
so the actual recommendation is: it's a good idea to instead use a pattern matching library like (chibi match). slay, much clearer, you'll thank yourself. β¨
π ERRORS π
this procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed, the argument was not a pair, or one of the intermediate links ofcarandcdrfields was not a pair. π©- R7RS β the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. π yes. catastrophically. that's the actual word. not a vibe.
π SEE ALSO π
caar(3scm)β the original icon herself π
β STANDARDS β
R4RS, IEEE Scheme, R5RS, R6RS, R7RS β she's certified everywhere, periodt. π
π 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/
and that's the whole page, bestie β¨ go forth and maybe use pattern matching instead π¦
sign-off: this cutie came from the scheme-manpages source, version dated 2020-04-18, and it's titled caaar(3scm) β love her, mean it π π
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2020 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms