Hi Torsten, On Wed, Jan 25, 2017 at 2:45 PM, Torsten Bergmann <[email protected]> wrote:
> Hi, > > From my perspective: > > - I agree with Igor that "once" can be interpreted as "evaluate it only > once" as in > "Halt once". > > - I'm not sure but from the (now very distributed) discussion it is not > clear to me if > the #once mentioned by Eliot really has exactly the same behavior as > #memoized in Pharo. > Let's separate the implementation from the semantics. Memorizing a function implies cacheing its results for some set of arguments and answering the results, avoiding evaluating the function again. This is the effectively same semantics as [expr] once, which says that expire will be evaluated exactly once. So they're both forms of memorization. I recognized this but was too stupid/tired to realize they weren't the same, since once applies to nullify blocks and memorize applies to Nary blocks. That started this whole discussion, apologies. Now, descending to the implementations, I understand that Ben's memorize answers a block that wraps a dictionary which caches the arguments -> results mappings. #once is implemented to use become to convert the block (which in VW must be a clean block) into a cacheingBlockClosure which has an extra inst var to hold its values. We can make this work in Squeak and Pharo because we now have a prototype for clean blocks. So, quite different implementations, but very similar semantics That brings me to mention that in VW there's another, rather elegant, use for the once style block tricks, and that is to speed up step into in the debugger. Currently the implementation of step into is to simulate election (that's Smalltalk executing the InstructionStream byte code execution code, byte code by byte code) until control either returns or enters a block in the current method. That's slooooooow. The alternative is for the debugger to find all the blocks in the method and change their classes to a subclass of BlockClosure that raises an exception on value, and then use the step over code to get the VM to execute the code (via perform:) until either control returns or the exception is raised. The debugger then changes all the classes back and sets the focus to the current method. This is fast. Of course things get hairy when one considers debugging the debugger, but its all about the particular debugger only halting execution if it sees the exception is raised by the current set of blocks it has changed the classes of, and uses #pass to ignore any others created by other debuggers. > Does it also return a block that is caching the results and avoids a > second evalution > of the original block when having similar inputs? Also is there a > similar possibility > to give an own cache as in #memoizedUsing: for further tuning? > > - #memoizing is really not well explaining what it does but this seems to > be the official > term (also in other languages like Python, Java, JS, ...): > https://en.wikipedia.org/wiki/Memoization > > - maybe #withMemo(r)izingResults or #withCachingResults, #withReusedResults, > ... or something along that line > would be more intention revealing selectors > > > Side note: > ========= > - For license reason it would not make much sense to look into non-open > Smalltalks > - I have no idea about the VW version (and for obvious reasons dont want > to have a look) > - also dont know about other dialects if they have built in support for > memoization but it would be > good if Squeak, Pharo, Cuis, ... could align for such a case > - IMHO if #once and Pharos #memoization really have the same behavior then > compatibility for VW users > could be easily retained by adding #once to existing compatibility > layers (like "Grease") > > Bye > T. > > Gesendet: Mittwoch, 25. Januar 2017 um 22:30 Uhr > Von: "Igor Stasenko" <[email protected]> > An: "Pharo Development List" <[email protected]> > Betreff: Re: [Pharo-dev] memoized vs once > > #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, Eliot
