pair?(3scm)
πΈ NAME πΈ
okay bestie, welcome to the pair?(3scm) page β yes, we're doing this. This is all about pair?, the little predicate that tests if an object is a pair. π
π LIBRARY π
you'll want one of these imports, depending on your Scheme era:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
β¨ SYNOPSIS β¨
(pair? obj)
π DESCRIPTION π
The pair? predicate returns #t if obj is a pair, and otherwise returns #f. That's it, no cap. πββοΈ
π RETURN VALUES π
Returns a single boolean object as per the description. literally one boolean, bestie.
π¦ EXAMPLES π¦
(pair? '(a . b)) => #t
(pair? '(a b c)) => #t
(pair? '()) => #f
(pair? '#(a b)) => #f
slay, look at those results.
πΈ APPLICATION USAGE πΈ
One of the most common uses of pair? is to destructure large data structures, to extract parts of them and to verify their structure. Larger structures are more conveniently destructured using a pattern matching library such as (chibi match). iykyk.
π RATIONALE π
The pair? predicate allows a program to walk over a data structure built from pairs. It also lets programs protect themselves against invalid calls to procedures that expect pairs, such as car(3scm). self-care, honestly. π«Ά
β COMPATIBILITY β
Not all predicates are guaranteed to be disjoint from this predicate. Implementations are free to use pairs to construct some of the kinds of objects described in the Scheme reports, such as conditions and promises. The disjointness of predicates differs between the Scheme reports. so yeah, check your report vibes. π
π§ ERRORS π§
This procedure can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed.- 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.
fail catastrophically is giving main character energy, but maybe don't. π
π SEE ALSO π
π STANDARDS π
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
π HISTORY π
Lisp has always tagged objects with a type. Early Lisp used pattern matching, an example of which is maplist from MIT AI Memo No. 4 (1958 or 1959). Early Lisp programs written in S-expressions used the null and atom predicates to test for the inverse of pair?, as in MIT AI Memo No. 14 (1959 or 1960). This style seems to have continued even until Scheme (MIT AI Memo No. 349, December 1975). The first Scheme report to have pair? is RRRS (MIT AI Memo No. 848, August 1985), and it was the first Scheme report to not assume an underlying MacLISP implementation. history lesson ate, fr fr. π
π 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/.
that's the whole page, bestie! mwah π β source/version: the scheme-manpages project, dated 2020-12-13, manual name pair?(3scm). π
π¦ 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