RosettaCodeData/Task/Fibonacci-sequence/Latitude/fibonacci-sequence-2.latitude

17 lines
342 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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.
}.