Posted to tcl by kbk at Fri Jun 12 20:20:55 GMT 2009view pretty
namespace path ::tcl::mathop proc fib {n {c {{x} {set x}}}} { while {$n >= 2} { set c [list [list x [list n $n] [list c $c]] { tailcall fib [- $n 2] [list [list y [list x $x] [list c $c]] { tailcall apply $c [+ $x $y] }] }] incr n -1 } tailcall apply $c $n } for {set i 0} {$i <= 10} {incr i} { puts [fib $i] }