25.2.4 Checking required conditions
The assert
command breaks out of a function with an error.
-
assert takes
bool, a boolean.
- assert(bool) does nothing if
bool is true, it returns from the function with an error if
bool is false.
Example
Define the function:
sqofpos(x):={ assert(x>0); return x^2; } |
then:
|
“assert failure: x>0 Error: Bad Argument Value”
| | | | | | | | | | |
|
since −4>0 is false.