On 26 January 2017 at 01:23, [email protected] <[email protected]> wrote:
> Nothing new, that's the term. > > Memoization: After computing a solution to a subproblem, store it in a > table. Subsequent calls check the table to avoid redoing work. > > https://en.wikipedia.org/wiki/Memoization > > http://www.cas.mcmaster.ca/~deza/6_Dynamic++.pdf > > http://wiki.tcl.tk/10779 > > I have been using the method for something else, caching costly REST calls. > > getIssueCreateMeta > "Retrieves the metadata for all types of issues. Fields are expanded" > ^ self isMemoizingMeta > ifTrue: [ ([ :ignored | self getIssueCreateMetaWithExpandKeys: true ] > memoizedUsing: self cache ) value: #issueCreateMeta ] > ifFalse: [ self getIssueCreateMetaWithExpandKeys: true ] > > > using: > > cache > ^ cache ifNil: [cache := LRUCache new maximumWeight: self > defaultCacheWeight ] > > It is nice to see the cache hit rate etc in the inspector. > > BTW I am interested to see how one coul dwrite the code above without > repeating the block. > Also, :ignored is not used by the method but is the cache key. > > well, for not repeating, its easy, for instance in NativeBoost i just used expressions like: getIssueCreateMeta ^ self cacheAt: somekey ifAbsentPut: [ some data ] which are self-explanatory (i hope) where somekey could be 'self' or whatever seem fit. as for the caching wihoout key, why not just store result of first evaluation and then use it directly anywhere else? why need to wrap it with block?? data := [some calculation ] value. self doSomethingWith: data. self doSomethingElseWith: data. self doSomethingElseElseWith: data. voila.. plain programming. Where does memoization need to be coined here? :) Phil > > On Wed, Jan 25, 2017 at 10:30 PM, Igor Stasenko <[email protected]> > wrote: > >> #once can be interpreted as 'evaluate it once', >> >> but i don't like the #memoized .. it sounds painful to my ears. >> It sounds like something stinking smeared across my face.. and i always >> got stuck,confused and lost as the meaning of it always >> escaping my mind, since it naturally defends itself from any unpleasant >> thoughts. >> >> IMHO, maybe #once is not the best wording for what it does , but >> #memoizing... yuck.. pardon me. >> >> :) >> >> >> -- >> Best regards, >> Igor Stasenko. >> > > -- Best regards, Igor Stasenko.
