TIP #53: Addition of 'assert' Command

Title:Addition of 'assert' Command
Version:$Revision: 1.4 $
Authors: Gerald W. Lester <Gerald dot Lester at aspentech dot com>
Kevin Kenny <kennykb at acm dot org>
Created:Tuesday, 14 August 2001
Keywords:bytecode, compiler


This TIP proposes the addition of an assert command and supporting infrastructure to the Tcl core.


Many languages, including other scripting languages, have assertion checking features that can be used to assist in validating program correctness. Typically, these assertion checking features can be "compiled out" of production systems so as not to impact performance. To have a similar effect in Tcl, the assertion checking features must be implemented at the byte code compiler level.

If, doing byte code compilation, an assert command is encountered the byte code stream generated will be dependent on the value of the assert_enabled command line option. If the option is true, a byte code stream will be emitted to implement the assert command. If the option is not true, no byte code will be emitted.

Similarly, if the interpreter encounters an assert command (either compiled or uncompiled), it will only execute it if the assert_enabled command line option is true.

It is acceptable for the compiler to throw an error if the booleanExpression is not brace quoted.

Tcl-Level Specification

The manual entry for the assert command is included here:


assert - Assert a run time validation condition


   assert booleanExpression messageText


This command has no effect if the assert_enabled command line option is not true at both compile and run time. If the assert_enabled command line option is true at both compile and run time, the following behavior will occur:

  1. The booleanExpression will be evaluated

    1. If the booleanExpression evaluates to a true value, assert::failed will be called at the global level with messageText as its one and only parameter.

      The default implementation of assert::failed will write messageText to standard out and exit with a status code of 1.


This TIP has been withdrawn because of other changes, both inside and outside the Tcl core.

  1. The bytecode compiler (8.4a4) contains code that recognizes a no-op procedure of the form proc no-op args {} and generates no bytecode if such a procedure is called with arguments that have no side effects.

  2. The control package within tcllib implements a ::control::assert procedure that provides all the requested functionality.

These two, taken together, provide an implementation of the requested functionality that is acceptable to the original author of this TIP.


This TIP is in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows