Created
January 15, 2011 05:10
-
-
Save tafsiri/780712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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