RosettaCodeData/Task/Fibonacci-sequence/Latitude/fibonacci-sequence-2.latitude
2023-07-01 13:44:08 -04:00

16 lines
342 B
Text

fibo := {
takes '[n].
cache := here cache.
{ cache slot? (n ordinal). } ifFalse {
cache slot (n ordinal) =
if { n <= 1. } then {
n.
} else {
fibo (n - 1) + fibo (n - 2).
}.
}.
cache slot (n ordinal).
} tap {
;; Attach the cache to the method object itself.
#'self cache := Object clone.
}.