RosettaCodeData/Task/Factorial/Tcl/factorial-1.tcl
2025-06-11 20:16:52 -04:00

12 lines
226 B
Tcl

# tailcall optimization is standard in tcl8.6
proc fact { n { result 1. } } {
if { $n <= 1 } {
return $result
} else {
tailcall fact [expr {$n-1}] [expr {$n*$result}]
}
}
set f [fact 10]
puts $f