On 7/22/2010 8:42 PM, commits(a)source.squeak.org wrote:
> 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
>
What am I missing?
Object compile: 'onceTest
"Just once please"
^[Transcript cr; show: ''only once''] once'.
#(1 2 3) collect: #onceTest.
Cheers,
- Andreas
On 2010/07/22 20:42, commits(a)source.squeak.org wrote:
> 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
So if I understand correctly, this allows a block to memoize itself but
also, unlike most memoization schemes, also allows us to UNmemoize the
block?
That's a pretty neat trick!
frank
The new image looks great. I think it hits all the right notes. I'll add a
link to the Documentation/Instructions part of squeak.org tomorrow, as
seaside.st is already pointing to that area. We can add other links on
squeak.org as well.
Chris
Andreas Raab uploaded a new version of Tests to project The Trunk:
http://source.squeak.org/trunk/Tests-ar.88.mcz
==================== Summary ====================
Name: Tests-ar.88
Author: ar
Time: 22 July 2010, 7:58:08.503 pm
UUID: 7a106762-fe28-7d4c-86a6-921c4a812193
Ancestors: Tests-ar.87
Add a test documenting an bug in UIManager>>edit:label:accept: which would evaluate the accept block initially.
=============== Diff against Tests-ar.87 ===============
Item was added:
+ ----- Method: MorphicUIBugTest>>testUIManagerNoAcceptInitially (in category 'as yet unclassified') -----
+ testUIManagerNoAcceptInitially
+ "Ensure that UIManager does not invoke the accept: action initially."
+
+ | accepted window |
+ accepted := false.
+ window := UIManager default edit: Text new label: 'Test' accept: [:val| accepted := true].
+ window delete.
+ self deny: accepted.!
Eliot Miranda uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-eem.353.mcz
==================== Summary ====================
Name: System-eem.353
Author: eem
Time: 22 July 2010, 5:53:14.999 pm
UUID: 6757175d-0063-4089-916c-4dfc0cc425c7
Ancestors: System-ar.352
Some Cog-specific VM attribute accessors for process
preemption, flagging of interpreted methods and whether
Process has a threadId inst var.
=============== Diff against System-ar.352 ===============
Item was added:
+ ----- Method: SmalltalkImage>>processHasThreadIdInstVar: (in category 'system attributes') -----
+ processHasThreadIdInstVar: aBoolean
+ "The threaded VM needs to know if the 4th inst var of Process
+ is threadId which it uses to control process-to-thread binding.
+ This flag persists across snapshots, stored in the image header."
+ aBoolean ifTrue: [self assert: (Process instVarNames at: 4) ='threadId'].
+ self vmParameterAt: 48 put: ((self vmParameterAt: 48) bitClear: 1) + (aBoolean ifTrue: [1] ifFalse: [0])!
Item was added:
+ ----- Method: SmalltalkImage>>processPreemptionYields (in category 'system attributes') -----
+ processPreemptionYields
+ "Answer whether the VM causes a process to yield on process preemption,
+ i.e. to put a preempted process at the back of its run queue. If the parameter
+ is unavailable (non-Cog VMs) or bit 2 (4) is 0 then preemption yields."
+
+ ^(([self vmParameterAt: 48]
+ on: Error
+ do: [:ex| ^true]) allMask: 4) not!
Item was added:
+ ----- Method: SmalltalkImage>>processPreemptionYields: (in category 'system attributes') -----
+ processPreemptionYields: aBoolean
+ "The Cog VM can be instructed not to yield on process preemption,
+ i.e. not to put a preempted process at the back of its run queue. By
+ default preempting a process causes it to yield (Blue Book semantics)
+ which can have unfortunate effects.
+ This flag persists across snapshots, stored in the image header."
+
+ self vmParameterAt: 48 put: ((self vmParameterAt: 48) bitClear: 4) + (aBoolean ifTrue: [0] ifFalse: [4])!
Item was added:
+ ----- Method: SmalltalkImage>>flagInterpretedMethods: (in category 'system attributes') -----
+ flagInterpretedMethods: aBoolean
+ "The Cog VM can be instructed to set the flag bit of CompiledMethods that
+ it executes but will only interpret. This can be used e.g. to profile startup.
+ See CompiledMethod>>#flag & CompiledMethod>>#clearFlag.
+ This flag persists across snapshots, stored in the image header."
+
+ self vmParameterAt: 48 put: ((self vmParameterAt: 48) bitClear: 2) + (aBoolean ifTrue: [2] ifFalse: [0])!
Just read the post from Hilaire about Pharo on OLPC [1].
This leads to the following interesting question:
What is the most crazy device Squeak VM is running on?
What is the most interesting application where nobody
would have expected Squeak/Pharo/Cuis?
Feel free to answer by posting screenshots/pictures even if
you think the device/app is boring. Would be nice to know
and we can collect these to do a little bit of advertising
on the Squeak/Pharo web pages...
Bye
T.
[1] http://blog.ofset.org/hilaire/index.php?post/2010/07/20/Pharo-Smalltalk-on-…
--
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
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!