package require quill 0.3.0 namespace import ::quill::*assert expression
Assertion failed: expressionAn assertion is a statement that verifies an invariant within a module of code. An invariant is a condition that must always be true within the module. Invariants should be checked in complex, state-ful code to make explicit the author's assumptions about what should be true at each point in time:
# At this point we should have at least one page. assert {$pageCount > 0}
An assertion failure always means that the implementor of the module made a programming error. Thus, assertions should not be used to check conditions beyond the programmer's control, such as existence of a file.
The primary use for this command is in tests that verify the error code.
By default, foroption extracts options until it reaches the first item in the listvar that doesn't begin with a hyphen ("-"). When it returns, the listvar contains any remaining arguments.
If the -all option is given, foroption expects the list to contain only options and their values, and will throw an error if the list is not empty when it is complete.
The command throws INVALID when it finds an unknown option.
For example,
array set opts { -flag 0 -num 0 } foroption opt argv -all { -flag { set opts($opt) 1 } -num { set opts($opt) [lshift argv] } }
Where assertions protect a module from itself, preconditions protect modules from their callers. A precondition is associated with one of the module's public entry points (i.e., a command) and specifies a condition that must logically be true if the command is to succeed. Preconditions should generally be checked at the head of the command's body, and the message should clearly indicate what's wrong.
A precondition failure always means that the caller of the module made a programming error. Thus, preconditions should not be used to check conditions beyond the programmer's control, such as existence of a file.
As an example of a useful precondition, consider a database object that can only be queried if it has created or opened a data file. The object's get method might use a precondition like this:
precond {$self isopen} "No database file is open."
Requirements are like preconditions on user input. Because a distinct error code is used, the user interface can distinguish between unexpected application errors and errors in user input.