Skip to content

Instantly share code, notes, and snippets.

@tafsiri
Created January 15, 2011 05:10
Show Gist options
  • Save tafsiri/780712 to your computer and use it in GitHub Desktop.
Save tafsiri/780712 to your computer and use it in GitHub Desktop.
fakeClosure := Object clone do(
memo := Map clone
fibmemo := block(num, #note 'blocks' are lexically scoped
memo atPut(0 asString, 0)
memo atPut(1 asString, 1)
fibhelp := method(num,
one := memo at((num-1) asString)
two := memo at((num-2) asString)
if(one == nil
, one = fibhelp(num-1,memo)
memo atPut((num-1) asString, one)
)
if(two == nil
, two = fibhelp(num-2,memo)
memo atPut((num-2) asString, two)
)
one + two
)
fibhelp(num,memo)
) setIsActivatable(true)
)
fibmemo := fakeClosure getSlot("fibmemo")
fibmemo(12) println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment