action
assert test-expression (message string-expression)?
You can use assert
to verify any assumptions you are making at any given point in your code. To
test an assumption, insert the word assert
at an appropriate point in your code and follow it with
a test expression that tests your assumption. If the test condition returns true
, your program
continues. If the test expression returns false
, OmniMark throws a run-time error. You
can specify an error message to accompany the error by adding a message
parameter:
global integer number-of-guesses initial { 10 } process assert number-of-guesses > 0 message "Illegal value for number-of-guesses" output "You have " || "d" % number-of-guesses || " guesses."
In this program the number of guesses is a global
and therefore configurable on the command line. The
assert
statement tests to make sure that it is not set to a value that does not make sense.