In article
<
c3b29c33-e4eb-4e31...@googlegroups.com>,
amin...@gmail.com wrote:
> Functional Programming Doesn't Work (and what to do about it)
>
> "After spending a long time in the functional programming world, and using
> Erlang as my go-to language for tricky problems, I've finally concluded that
> purely functional programming isn't worth it."
Functional programming with memoing does.
A(0, 0) = 1, 1 iterations.
M(0, 0) = 1, 1 iterations.
A(4, 0) = 13, 107 iterations.
M(4, 0) = 13, 33 iterations.
A(0, 4) = 5, 1 iterations.
M(0, 4) = 5, 0 iterations.
A(1, 1) = 3, 4 iterations.
M(1, 1) = 3, 0 iterations.
A(2, 2) = 7, 27 iterations.
M(2, 2) = 7, 0 iterations.
A(3, 4) = 125, 10307 iterations.
M(3, 4) = 125, 283 iterations.
set ak 0
proc A {m n} {
incr ::ak
expr {
$m==0 ? [+1 $n]
: $n==0 ? [A [-1 $m] 1]
: [A [-1 $m] [A $m [-1 $n]]]
}
}
set mk 0
array set memo {}
proc M {m n} {
global memo
if {[info exists memo($m,$n)]} {return $memo($m,$n)}
incr ::mk
set Mmn [expr {
$m==0 ? [+1 $n]
: $n==0 ? [M [-1 $m] 1]
: [M [-1 $m] [M $m [-1 $n]]]
}]
set memo($m,$n) $Mmn
return $Mmn
}
proc +1 {v} {expr {$v+1}}
proc -1 {v} {expr {$v-1}}
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
The first law of discordiamism: The more energy This post / \
to make order is nore energy made into entropy. insults Islam. Mohammed