Scope/Function names and labels: Difference between revisions

→‎Tcl: Added description
m (whitespace)
(→‎Tcl: Added description)
Line 126:
 
add.2.args: procedure; parse arg x,y; return x+y</lang>
 
=={{header|Tcl}}==
There are a number of different symbol types in Tcl, all of which are handled independently. Each namespace contains a mapping from (simple) command names to command implementations; when a command is looked up, the search is done by looking in the current namespace, then in the namespaces on that namespace's path (which is usually empty), and finally in the global namespace. There are ''no'' local commands (unlike with variables, though a lambda expression in a variable can act very similarly to a command). Commands only have a mapping after they have been created; the <code>proc</code> “declaration” is just a command that creates a procedure at the point where it is called.
<lang tcl>doFoo 1 2 3; # Will produce an error
 
proc doFoo {a b c} {
puts [expr {$a + $b*$c}]
}
doFoo 1 2 3; # Will now print 7 (and will continue to do so until doFoo is renamed or deleted</lang>
Tcl does not support labels, either outside or inside procedures. (Other mechanisms are used for jumps and state machines.)
 
=={{header|ZX Spectrum Basic}}==
Anonymous user