16 lines
342 B
Text
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.
|
|
}.
|