Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Anonymous-recursion/Tcl/anonymous-recursion-1.tcl
Normal file
10
Task/Anonymous-recursion/Tcl/anonymous-recursion-1.tcl
Normal 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
|
||||
}
|
||||
1
Task/Anonymous-recursion/Tcl/anonymous-recursion-2.tcl
Normal file
1
Task/Anonymous-recursion/Tcl/anonymous-recursion-2.tcl
Normal file
|
|
@ -0,0 +1 @@
|
|||
puts [fib 12]
|
||||
9
Task/Anonymous-recursion/Tcl/anonymous-recursion-3.tcl
Normal file
9
Task/Anonymous-recursion/Tcl/anonymous-recursion-3.tcl
Normal 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
|
||||
}
|
||||
8
Task/Anonymous-recursion/Tcl/anonymous-recursion-4.tcl
Normal file
8
Task/Anonymous-recursion/Tcl/anonymous-recursion-4.tcl
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue