Version 9 of Tcl procedure

Updated 2008-06-27 11:49:18 by LV

Some of Tcl's documentation refers to procedures as a distinct type of command.

A procedure is a Tcl command that is created by the proc command.

For example the info args command expects its argument to be the name of a procedure. Names of non-proc commands, variables, etc. passed to info args will cause an error to be raised.

Likewise, info body command expects an argument of the name of a procedure.


Some languages (e.g. Pascal) uses the terms "function" and "procedure" to denote subroutines which do and don't respectively return a value. In Tcl, the distinction is quite different: a function is a subroutine available in expressions (and as of Tcl 8.5 these are merely implemented by commands in the tcl::mathfunc namespace). A procedure is a command created by proc, and like any other command it returns a value. In the absence of an explicit return, this value is simply the value returned by the last command in the procedure body.


See also Pass by reference and Implicit upvar.