assert - raise an assertion violation if an expression is false
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
SYNOPSIS
(assert expression)
DESCRIPTION
An
assert
form is evaluated by evaluating
expression.
If
expression
returns #f, an exception with condition types &assertion and &message
is raised. The message provided in the condition object is
implementation-dependent.
IMPLEMENTATION NOTES
- Ikarus Scheme
-
See "BUGS".
RETURN VALUES
If
expression
returns a true value, that value is returned
from the
assert
expression.
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
APPLICATION USAGE
Applications can use this form to guard against invalid uses of
procedures. It is often more convenient than manual use of
assertion-violation.
RATIONALE
Implementations can exploit the fact that
assert
is syntax to provide as much information as possible about the
location of the assertion failure.
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.
- &syntax (R6RS)
-
More or fewer than one expression was passed.
SEE ALSO
assertion-violation(3scm)
STANDARDS
R6RS
HISTORY
The assert macro is new in R6RS, but has a long history in programming.
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/
.
BUGS
The implementation in psyntax from the r6rs-libraries project is buggy
and does not return the true value. This bug has spread into some
Scheme compilers.
Markup created by unroff 1.0sc, March 04, 2023.