reverse(3scm)
π 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms