Function definition: Difference between revisions

Content added Content deleted
(→‎{{header|Tcl}}: formatting, do a function as opposed to a procedure...)
Line 516: Line 516:


Strictly as described in the task:
Strictly as described in the task:
<lang tcl>proc multiply { arg1 arg2 } {
return [expr {$arg1 * $arg2}]
}</lang>
{{works with|Tcl|8.5}} <br>
You can also create functions that work directly inside expressions. This is done by creating the command with the correct name:
<lang tcl>proc tcl::mathfunc::multiply {arg1 arg2} {
return [expr {$arg1 * $arg2}]
}


# Demonstrating...
proc multiply { arg1 arg2 } {
if {multiply(6, 9) == 42} {
return [expr $arg1 * $arg2]
puts "Welcome, Citizens of Golgafrincham from the B-Ark!"
}
}</lang>


=={{header|Toka}}==
=={{header|Toka}}==