Hi Eliot. 2017-01-25 19:56 GMT+01:00 Eliot Miranda <eliot.miranda@gmail.com>:
Hi Ben,
via FaceBook via twitter I hear you've coined BlockClosure>>#memoized. Allow me to beg you to rename it to BlockClosure>>#once. There's a preexisting implementation of this in VisualWorks by Travis Griggs called once. I hope you agree that it's good to eliminate gratuitous incompatibilities between dialects and that "once" is an elegant name.
#once is not the same as #memoized. #memoized returns another block which wrap original one to perform some caching. Actually I not understand logic behind it. But #once supposed to evaluate receiver while #memoized creates new block. In Pharo 6 I pushed new method #asMethodConst. Unfortunately I was not aware about #once from VisualWorks at this time and reviewers too. But #asMethodConst is a bit different. It is Object method instead of Block. And it is based on AST modification. When asMethodConst is executed it replace executing AST-node of sender with receiver which produce new method where full message node is replaced by result as literal. I put mode details here http://dionisiydk.blogspot.fr/2016/07/magic-with-pharo-reflectivity.html. In short you can write expressions like: 10 factorial asMethodConst