Darwin Help

Back to Index

assert

Function assert - test that an assertion is true

Calling Sequence  assert(cond)
Parameters
NameTypeDescription

cond booleana condition to be tested
Return Type  NULL
Synopsis This function evaluates its argument, which is expected to be true or false. If it evaluates to true, it does nothing. If it evaluates to false it produces an "assertion failed" error. The first argument of the error is the unevaluated expression that evaluated to false. It is the easy to write assertions which upon failure will automatically produce meaningful errors.
Examples
> assert(1=2);;
Error, 1 = 2, assertion failed
> Probab := 1.001;
Probab := 1.0010
> e := [ traperror(assert( Probab >=0 and Probab <= 1))];
e := [0 <= Probab and Probab <= 1, assertion failed]
> length(e);
2
> e[1];
0 <= Probab and Probab <= 1


See also error,   lasterror,   traperror