Version 9 of procedure

Updated 2021-06-21 07:47:24 by pooryorick

In Tcl, a procedure is a routine that can be named by the first word in a command. proc creates a new procedure, and so do the C functions Tcl_CreateObjCommand() and friends. info commands provides a list of available procedures, and info procs provides a list of available procedures that were created by proc.

Description

RS: A procedure is a script with an argument list (in other words, a lambda) bound to a command name, by which it can be called. The arguments make the initial set of local variables, to which you might add others. All of these will be removed on leaving the procedure. See global or variable or upvar on how to "import" variables from upper scopes. In Tcl, procedures are defined with the proc command, for example:

proc myproc {arg1 arg2} {
    # do something here, e.g.
    puts arg1:$arg1,arg2:$arg2
}

Each procedure returns a result, which means tht in Tcl, every procedure is also a function. If there is no explicit return, then the result of the last command is the result of the procedure.