pair?(3scm)

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

🌸 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 πŸ‘‘

car(3scm), cons(3scm)

🌟 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