Fibonacci numbers in Tcl
Example for versions
ActiveTcl 8.5,
Tcl 8.5.7
This example uses iterative definition of Fibonacci numbers. lassign
assigns successive elements from the list passed as first argument (created by [list ...]
) to the variables given by the next arguments (fib1
and fib2
in this case). This command was moved to language core in Tcl 8.5; before that it was part of TclX package.
set fib1 0
set fib2 1
set s ""
for {set i 0} {$i < 16} {incr i} {
lassign [list $fib2 [incr fib2 $fib1]] fib1 fib2
append s "$fib1, "
}
puts "$s..."
Comments
]]>blog comments powered by Disqus
]]>