spade-0.1.0.10: samples/fib-cache.spd
let cache = newref({})
proc fib(n)
if (n < 1) then
return 1
else
let c = readref(cache)
if haskey(c, tostring(n)) then
return c[tostring(n)]
else
let r = (fib((n - 1)) + fib((n - 2)))
modifyref(cache, fn (c) addkey(c, tostring(n), r) endfn)
return r
endif
endif
endproc
println(fib(135))