proc — Create a new procedure.
proc
[name
]
arglist
body
The proc command creates new procedures, which are virtually
indistinguishable from built-in Hecl
commands.
is the name of the new
command, or, if it is absent, an anonymous procedure is created (and should be stored in a
variable).
name
is a
list of arguments that the new command will take and make
available as local variables within the
arglist
, which is
the code executed every time the command is called. If the
last element of the argument list is body
args
,
the variable args
is a list that is
filled with any arguments (including 0) above and beyond the
number of arguments specified for the proc.
proc addlist {lst} { set res 0 foreach e $lst { incr $res $e } return $res } puts [addlist {1 2 3 4 5}]
Produces:
15