assert(3scm)
π assert(3scm) β the Scheme Programmer's Manual, but make it cute
okay bestie, so this is assert(3scm) from the Scheme Programmer's Manual β and honestly? she's lowkey iconic. let's get into it π«Ά
β¨ NAME β¨
assert β raises an assertion violation when an expression comes back false. that's it, that's the gig π
π LIBRARY π
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
both of these give you assert, so pick your vibe β¨
π SYNOPSIS π
(assert expression)
one expression, no notes π
π¦ DESCRIPTION π¦
so the way assert works is: it's a form, and evaluating it means evaluating expression. main character energy, right?
here's the tea though β if expression returns #f, an exception gets raised, and it carries the condition types &assertion and &message. slay for error handling.
ngl, the message that ends up inside that condition object is implementation-dependent β so don't come for the spec about it, she never promised you specific wording π
π§ IMPLEMENTATION NOTES π§
- Ikarus Scheme β see
BUGS. yeah. that's the whole note. go look. π
πΈ RETURN VALUES πΈ
if expression returns a true value, then that value is what the assert expression returns. periodt. you get your value back, no cap π
β EXAMPLES β
(define (integer-add x y)
(assert (and (integer? x) (integer? y)))
(+ x y))
(integer-add 1 2)
=> 3
(integer-add 1 2.1)
=> raises &assertion and &message
see how 1 2 ate and left no crumbs? and 1 2.1? caught in 4K with a &assertion and a &message π¨ love that for us.
π APPLICATION USAGE π
apps can use this form to guard against invalid uses of procedures β like a little velvet rope at the door π it's often more convenient than manually calling assertion-violation, fr fr.
π RATIONALE π
the big brain move here: because assert is syntax, implementations can exploit that fact to give you as much information as possible about where the assertion failure happened. positional info, on the house β¨
π¨ ERRORS π¨
this procedure can raise exceptions with these condition types:
&assertion(R6RS) β the wrong number of arguments was passed, or an argument was outside its domain. classic.&syntax(R6RS) β more or fewer than one expression was passed. one expression. one. i'm not asking twice π
π SEE ALSO π
π STANDARDS π
R6RS π
π°οΈ HISTORY π°οΈ
the assert macro is new in R6RS, but honestly she has a long history in programming. not a newbie, just newly specced β¨
π«Ά AUTHORS π«Ά
this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more info can be found at https://github.com/schemedoc/manpages/. go show them some love π₯Ή
π BUGS π
the implementation inpsyntaxfrom ther6rs-librariesproject is buggy and does not return the true value. and unfortunately this bug has spread into some Scheme compilers. not the contagion π wash your hands, compilers.
and that's the page!! footer nation: this was 2020-09-05, version assert(3scm) β mwah, drink water, and remember to actually check your expressions before you assert them πππ¦π·
π¦ 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