condition(3scm)

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

πŸ’… condition(3scm) β€” like, the compound conditions page, bestie

okay so this is condition(3scm) from the Scheme Programmer's Manual, and it's lowkey one of the most useful little procedures in the whole condition system. we're gonna get into it, don't worry 🫢


✨ NAME ✨

condition β€” compound conditions, aka ✨the multipack✨ of condition objects

πŸ“š LIBRARY πŸ“š

bestie you gotta import it first, no cap:

(import (rnrs))                     ;R6RS
(import (rnrs conditions))          ;R6RS

🩷 SYNOPSIS 🩷

(condition condition1 ...)

🌸 DESCRIPTION 🌸

So condition takes a bunch of conditions (yes, condition1 and friends) and returns one condition object that's made up of all their components as its components β€” and the order is preserved, fr fr. like, the components of condition1 show up first, in the exact same order they had inside condition1, then the components of condition2 come next, and so on down the line. it's giving "stack them in a row and don't shuffle" πŸ’…

and here's the iconic part: these compound conditions act as if they were any of the simple conditions tucked inside them, as far as predicates and accessors go. so if you ask "are you an error?" or "are you a message?", the compound one is like "yeah, technically, through one of my components" 😌 main character energy honestly.

πŸŽ€ RETURN VALUES πŸŽ€

returns a single value β€” one condition. that returned condition is compound if the total number of components is zero or greater than one. otherwise (i.e. exactly one component, you get the vibe), it may be compound or simple. so like, don't assume, okay? πŸ™ˆ

πŸ¦‹ EXAMPLES πŸ¦‹

look at this beauty:

(define con
  (condition
   (make-error)
   (make-message-condition "I am an error")))

(error? con)  =>  #t
(message? con)  =>  #t
(condition-message con)  =>  "I am an error"

see?? it ate. con is both an error and a message condition at the same time, and condition-message still pulls the string right out. obsessed ⭐

πŸ”₯ APPLICATION USAGE πŸ”₯

compound conditions are your girl when you need to describe multiple aspects of an exceptional situation. you pass them to raise(3scm) and raise-continuable(3scm), and they're normally caught with guard(7scm). that's the whole workflow, iykyk πŸ’œ

🌈 COMPATIBILITY 🌈

compound conditions are unique to R6RS. nobody else has them. exclusive club, periodt. πŸ‘‘

πŸ’€ ERRORS πŸ’€

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” you passed the wrong number of arguments, or an argument was outside its domain. bestie. count your args. 😭

πŸ‘€ SEE ALSO πŸ‘€

  • simple-conditions(3scm) β€” go read that one too, it's the sibling

⭐ STANDARDS ⭐

R6RS 🫢

🧚 HISTORY 🧚

this procedure was first introduced in R6RS as part of the new condition system. so it's a glow-up baby, born fully iconic ✨

πŸ“ AUTHORS πŸ“

this page is part of the scheme-manpages project β€” it includes materials from the RnRS documents, and more info lives at https://github.com/schemedoc/manpages/ πŸ’–


ok that's the whole page, go forth and compound your conditions responsibly 🌸

and that's a wrap, bestie β€” brought to you by the 2022-05-14 edition of condition(3scm), mwah πŸ’…πŸŽ€

πŸ“¦ where this page comes from