programming.nbk: Home | Index | Next Page: Tcl: puts | Previous Page: Tcl: pattern matching


 Tcl: procedures

The basic syntax of a Tcl procedure declaration is:

    procedure_name arg_list body

    #this is good old recursive factorial
    proc factorial {number} {
        if { $number == 0 } {
	        return 1
        } else {                 
	        return [expr $number * [factorial [expr $number - 1]]]
        }
    }
    % factorial 10
    3628800

Curly brackets are used to group the argument(s) and to group the body of the procedure.


programming.nbk: Home | Index | Next Page: Tcl: puts | Previous Page: Tcl: pattern matching


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time