[Pkg] The Trunk: Kernel-eem.474.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Jul 22 20:42:43 UTC 2010
Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-eem.474.mcz
==================== Summary ====================
Name: Kernel-eem.474
Author: eem
Time: 22 July 2010, 1:42:05.4 pm
UUID: 292f2cc5-ba81-4d03-a64f-4e7cb878d68f
Ancestors: Kernel-eem.473
BlockClosure>>#once Travis Griggs' neat idiom for interning values of computations. Use e.g. as in
myResourceMethod
^[time-consuming computation] once
=============== Diff against Kernel-eem.473 ===============
Item was added:
+ ----- Method: CachedBlockClosure>>value (in category 'evaluating') -----
+ value
+ ^cachedValue!
Item was added:
+ ----- Method: BlockClosure>>becomeUncached (in category 'private') -----
+ becomeUncached
+ "The receiver is already uncached."
+ ^self!
Item was added:
+ ----- Method: CachedBlockClosure>>becomeCached (in category 'private') -----
+ becomeCached
+ "The receiver is already cached."
+ ^self!
Item was added:
+ ----- Method: BlockClosure>>becomeCached (in category 'private') -----
+ becomeCached
+ self become: ((CachedBlockClosure new: self size)
+ outerContext: outerContext
+ startpc: startpc
+ numArgs: numArgs
+ cachedValue: self value
+ copiedValues: self)!
Item was added:
+ BlockClosure variableSubclass: #CachedBlockClosure
+ instanceVariableNames: 'cachedValue'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Kernel-Methods'!
+
+ !CachedBlockClosure commentStamp: 'eem 7/22/2010 12:34' prior: 0!
+ I'm a BlockClosure with an added instance variable for storing the once upon a time result of evaluating myself when I was simple BlockClosure. This is triggered by sending #once to a normal BlockClosure. Future sends of once will simply return this value rather than evaluate myself. When sent value, I revert back to a BlockClosure. Originally by Travis Griggs, from whom we copy this idea with thanks.
+
+ Instance Variables
+ cachedValue <Object>
+
+ cachedValue
+ - result of having sent value to myself when i was just a BlockClosure!
Item was added:
+ ----- Method: CachedBlockClosure>>once (in category 'evaluating') -----
+ once
+ ^cachedValue!
Item was added:
+ ----- Method: CachedBlockClosure>>outerContext:startpc:numArgs:cachedValue:copiedValues: (in category 'initialize-release') -----
+ outerContext: aContext startpc: aStartpc numArgs: argCount cachedValue: aValue copiedValues: anArrayOrNil
+ cachedValue := aValue.
+ super outerContext: aContext startpc: aStartpc numArgs: argCount copiedValues: anArrayOrNil!
Item was added:
+ ----- Method: CachedBlockClosure>>becomeUncached (in category 'private') -----
+ becomeUncached
+ self become: (BlockClosure
+ outerContext: outerContext
+ startpc: startpc
+ numArgs: numArgs
+ copiedValues: self)!
Item was added:
+ ----- Method: BlockClosure>>once (in category 'evaluating') -----
+ once
+ "Answer and remember my value, answering exactly the same object in any further sends
+ of once or value until I become uncached. This allows one to intern values with the idiom
+ myResourceMethod
+ ^[expression] once.
+ The expression will be evaluated once and its result returned for any subsequent evaluations.
+ Originally by Travis Griggs, from whom we copy this idea with thanks."
+ numArgs ~= 0 ifTrue:
+ [self error: 'once should only be used with niladic blocks'].
+ self becomeCached.
+ ^self once!
More information about the Packages
mailing list