record-predicate(3scm)

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

πŸŽ€ record-predicate(3scm) πŸŽ€

okay bestie, welcome to the Scheme Programmer's Manual page for record-predicate β€” this one is lowkey tiny but highkey useful, and it's giving "record type vibe check." πŸ’…


🌸 NAME 🌸

record-predicate β€” create record predicates. No cap, that's the whole name section. 🫢


🌈 LIBRARY 🌈

okay so you import one of these depending on your setup, and yes, both are R6RS:

(import (rnrs))                     ;R6RS
(import (rnrs records procedural))  ;R6RS

✨ SYNOPSIS ✨

(record-predicate rtd)

πŸ’– DESCRIPTION πŸ’–

So record-predicate returns a procedure. Give that procedure an object obj, and it returns #t if obj is a record of the type represented by rtd, and #f otherwise. That's it β€” a little yes/no machine for records, and honestly? iconic. πŸ”₯


πŸ¦‹ RETURN VALUES πŸ¦‹

Returns a single value; a procedure. That's the whole return value, bestie β€” one procedure, no extra baggage. πŸ’…


πŸ“ EXAMPLES πŸ“

here's the exact example, bestie β€” copy it, run it, live your truth:

(define rtd-user
  (make-record-type-descriptor
    'user #f #f #f #f
    '#((immutable login) (immutable realname))))
(define rcd-user
  (make-record-constructor-descriptor
    rtd-user #f
    (lambda (p)
      (lambda (login realname)
        (p login realname)))))
(define make-user (record-constructor rcd-user))
(define user? (record-predicate rtd-user))

(define lain (make-user 'lain "Lain Iwakura"))
(user? lain)  =>  #t

🧚 APPLICATION USAGE 🧚

These procedures are used together with the procedural record layer. That's the application usage, and it's giving "we ride together, we record together." 🫢


πŸ’œ COMPATIBILITY πŸ’œ

This procedure is unique to the R6RS record system. An equivalent procedure can be found in SRFI-237. So if you're in R6RS land, you're chilling; if not, SRFI-237 has your back. ✨


⭐ ERRORS ⭐

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” The wrong number of arguments was passed or an argument was outside its domain. In particular, rtd must be a record-type descriptor. So yeah, don't hand it random nonsense and expect peace, okay? 😭

πŸ‘‘ SEE ALSO πŸ‘‘

go read these too, bestie:


🌟 STANDARDS 🌟

R6RS. periodt. πŸ’…


πŸŽ€ HISTORY πŸŽ€

First appeared in R6RS as part of the new record system. A little origin story, a little lore. πŸ¦‹


🌸 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 a wrap, bestie β€” source/version: Scheme Programmer's Manual, date: 2023-08-05, page: record-predicate(3scm). Mwah! 🫢

πŸ“¦ where this page comes from