list?(3scm)
π list? β check if an object is a list π
okay so bestie, welcome to list?(3scm), the Scheme Programmer's Manual page that is genuinely about to make you feel so much better about your code. let's get into it β¨
πΈ LIBRARY πΈ
like, where do you even import this from? here's the whole lineup, no cap:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
pick your vibe, they all got you π«Ά
β¨ SYNOPSIS β¨
(list? obj)
that's it. that's the whole call. iconic behavior honestly π
π¦ DESCRIPTION π¦
so list? returns #t if obj is a list, and #f otherwise. boom. done. but wait, what even is a list, you ask? by definition, all lists are chains of pairs that have finite length and are terminated by the empty list. literally the definition. write it down π
π§ IMPLEMENTATION NOTES π§
okay this part is lowkey cool. this procedure is expected to run in time linear to the number of elements in the list, which, slay. and implementations can be expected to use an algorithm like Floyd's cycle-finding algorithm β aka "tortoise and hare" π’π β which handles the case of circular lists created with set-cdr!(3scm). so like, if you made a cursed little ouroboros of a list, this thing still knows what's up. π₯
π RETURN VALUES π
returns a boolean object. #t or #f. no in-between, no "it's complicated", no situationship. π
π EXAMPLES π
here's where it gets fun, bestie:
(list? '(a b c)) => #t
(list? '()) => #t
(list? '(a . b)) => #f
(let ((x (list 'a)))
(set-cdr! x x)
(list? x)) => #f
see that last one?? that's the circular list situation, and list? said "not today" π periodt.
π COMPATIBILITY π
the list? procedure is identical in all revisions of the Scheme reports (we love consistency π). and IEEE Scheme explicitly mentions the case of circular structures β so yeah, this was foreseen. π
π ERRORS π
this procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed. like, you gave it too many or too few. read the synopsis bestie, it takes one π€- 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. catastrophic failure. no big deal. (it's a big deal.)
π₯ SEE ALSO π₯
pair?(3scm)β the other one. you'll want it. trust. iykyk π
β STANDARDS β
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
all of them. every single one. ate and left no crumbs. π
πΈ HISTORY πΈ
the list? procedure first appeared in R4RS. baby's first appearance π₯Ήπ¦
π 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/. go give them your love π«Άβ¨
π BUGS π
ngl, there's one mistake that is fairly common: calling list? when you're destructuring an object β like, immediately before using car(3scm) or cdr(3scm). don't do that. π use pair?(3scm) instead. that's the whole note. save it to your notes app fr fr.
okay that's the page!! stay curious, stay caffeinated, and please stop making circular lists with set-cdr! unless you really mean it ππ
β cute little sign-off: this page is dated 2022-03-23 and it belongs to list?(3scm), 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