append(3scm)

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

πŸŽ€ append(3scm) πŸŽ€

okay bestie, welcome to the append(3scm) page from the Scheme Programmer's Manual β€” this is the little icon that glues your lists together and it's genuinely SO useful, i'm obsessed. let's get into it πŸ’–


✨ NAME ✨

append β€” appends an object onto one list, or smashes multiple lists together. it's giving "group project but everyone actually shows up" 🫢


πŸ“š LIBRARY πŸ“š

like, which import do you need? here's the tea, one of these:

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

pick your era, they all serve πŸ’…


🌸 SYNOPSIS 🌸

(append)
(append list ... obj)

that's it. that's the whole vibe check. ⭐


πŸ’« DESCRIPTION πŸ’«

So append returns a possibly improper list β€” and the way it builds it is: all the elements of the first list, then all the elements of the other lists, and then obj gets stapled on as the cdr of that final pair. no cap.

If obj is not a list, you get an improper list out of it. that's just how it do. πŸ¦‹

Called with zero arguments? you get the empty list back. (append) is literally just (). periodt.

And here's the detail that lowkey matters a lot: the return value is made from new pairs for every argument except the last one β€” the last one is merely placed at the end of the new structure. so like, the last argument isn't copied, it's just... relocated. main character energy, it gets to keep its own identity. πŸ‘‘


🎁 RETURN VALUES 🎁

Returns a single value. If obj isn't a proper list, what comes back is an improper list. that's it, one value, no surprises (well, the improper-list thing, but we covered that). πŸ’œ


πŸ”₯ EXAMPLES πŸ”₯

these are the receipts, run them in your head and watch it slay:

(append '(x) '(y))         =>  (x y)
(append '(a) '(b c d))     =>  (a b c d)
(append '(a (b)) '((c)))   =>  (a (b) (c))
(append '(a b) '(c . d))   =>  (a b c . d)
(append '() 'a)            =>  a
(append)                   =>  ()
(append 'a)                =>  a

look at that last one. (append 'a) returns a. no list. just a. iconic, honestly. 😭


🌈 COMPATIBILITY 🌈

except for differences in error behavior, this procedure works the same everywhere. so like, the vibes are portable, the error handling is where implementations get quirky. πŸ™ˆ


πŸ’€ ERRORS πŸ’€

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. you did too much, bestie.
  • 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. yeah. catastrophically. no pressure. πŸ”₯
fr fr, that "fail catastrophically" line is not a joke, don't be out here passing nonsense and expecting mercy.

🫢 SEE ALSO 🫢

go read these next, they're the friend group:


⭐ STANDARDS ⭐

R4RS, IEEE Scheme, R5RS, R6RS, R7RS. certified everywhere. πŸ’…


🧚 HISTORY 🧚

okay history time, and it's kind of a flex: the append procedure has existed in LISP since at least 1959. iykyk. πŸŽ€

the variants before R3RS only accepted proper lists. then Scheme before R2RS, running on MacLISP, would accept any number of arguments β€” while in LISP 1.5 the procedure only accepted two arguments. two! that's it! imagine the restraint. 😭


πŸ‘‘ 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 append responsibly πŸ’–βœ¨πŸŒΈ

sign-off: this was append(3scm), dated 2023-02-08, from the scheme-manpages project. love u, bye! πŸŽ€

πŸ“¦ where this page comes from