Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,10 @@
proc fib n {
# sanity checks
if {[incr n 0] < 0} {error "argument may not be negative"}
apply {x {
if {$x < 2} {return $x}
# Extract the lambda term from the stack introspector for brevity
set f [lindex [info level 0] 1]
expr {[apply $f [incr x -1]] + [apply $f [incr x -1]]}
}} $n
}

View file

@ -0,0 +1 @@
puts [fib 12]

View file

@ -0,0 +1,9 @@
proc fib n {
if {[incr n 0] < 0} {error "argument may not be negative"}
apply {x {expr {
$x < 2
? $x
: [apply [lindex [info level 0] 1] [incr x -1]]
+ [apply [lindex [info level 0] 1] [incr x -1]]
}}} $n
}

View file

@ -0,0 +1,8 @@
# Pick the lambda term out of the introspected caller's stack frame
proc tcl::mathfunc::recurse args {apply [lindex [info level -1] 1] {*}$args}
proc fib n {
if {[incr n 0] < 0} {error "argument may not be negative"}
apply {x {expr {
$x < 2 ? $x : recurse([incr x -1]) + recurse([incr x -1])
}}} $n
}