reverse(3scm)

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

πŸ’œ reverse(3scm) β€” the Scheme Programmer's Manual, but make it cute

okay so bestie, welcome to the reverse glow-up page ✨ this is a page from the Scheme Programmer's Manual and it's literally about flipping a list around. baby's first functional one-liner, but there's lore πŸ‘‘

πŸ¦‹ NAME πŸ¦‹

reverse β€” reverse a list. that's it. that's the whole thing. iconic behavior honestly πŸ’…

πŸŽ€ LIBRARY πŸŽ€

like, where do you even find this queen? here:

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

pick your era, she serves in all of them 🫢

⭐ SYNOPSIS ⭐

(reverse list)

🌸 DESCRIPTION 🌸

reverse hands you back a newly allocated list (yes, freshly allocated, she's brand new, not a hand-me-down) whose elements are the elements of list β€” but in reverse order. first becomes last, last becomes first, main character energy all around πŸ’–

🧚 R6RS though 🧚

R6RS implementations must verify that list is a proper list. like, it's not optional, it's the law. no cap.

πŸ’€ IMPLEMENTATION NOTES πŸ’€

Chibi Scheme

  • Circular lists are not detected β€” she will not save you, bestie 😭
  • Improper lists are handled as if they were terminated by the last non-pair in the chain. so, quirky handling, not a crash.

✨ RETURN VALUES ✨

Returns a single value. a list. one (1) list. that's it πŸŽ€

🌈 EXAMPLES 🌈

watch her eat:

(reverse '(a b c))
        => (c b a)

and the nesting? obsessed:

(reverse '(a (b c) d (e (f))))
        => ((e (f)) d (b c) a)

πŸ”₯ COMPATIBILITY πŸ”₯

In R6RS implementations, the following code is guaranteed to raise an exception. (guaranteed!! she said what she said.) Non-R6RS implementations will commonly detect the problem, or loop until the process runs out of memory 🫠 β€” so like, don't be surprised.

(import (rnrs) (rnrs mutable-pairs))

(let ((xs (list 1 2)))
  (set-cdr! (cdr xs) xs)
  (reverse xs))
that's a circular list btw. you built a little ouroboros. R6RS says "absolutely not" πŸ’…

😭 ERRORS 😭

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed or the argument was not a proper list. rude of you, but okay.
  • 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, "fail catastrophically" is the actual wording, she's dramatic like that πŸ’€)

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group fr fr 🫢

πŸ“ STANDARDS πŸ“

R4RS, IEEE Scheme, R5RS, R6RS, R7RS. she's certified. credentialed. certified baddie across five standards πŸ’…

🧚 HISTORY 🧚

This procedure was already present in the first versions of Scheme β€” even those running on MacLisp. It was also present in LISP 1.5. so yeah, she's been reversing lists since before your fave was born. legacy. 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/.


k that's the page bestie, go reverse something πŸ’–βœ¨

sign-off szn: this glorious little doc is dated 2022-04-21 and it's the reverse(3scm) page from the Scheme Programmer's Manual β€” catch you in the next one, mwah πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from