Re: [Pharo-users] how to test, if the class has "shared identity" of instances in the whole image (SmallIntegers, Symbols...)
It is not clear to me what the semantics of such a selector would be. Consider this example: t := [:x | x copy == x]. a := t value: 1.0e38. b := t value: 1.0e308. What do you expect a and b to be? GNU Smalltalk: a=true, b=true. My Smalltalk, 32-bit or 64-bit: a=true, b=true. Squeak/Pharo, 32-bit: a=false, b=false. Squeak/Pharo, 64-bit: a=true, b=false. Squeak/Pharo, after a patch: a=true, b=true. There are two quite different reasons why x copy == x might be true: * x is immutable (including its parts), and can be thought of as a mathematical value, so that there is no need to copy it Examples: every kind of number, characters, booleans, immutable collections, block closures * x is a way of accessing a unique resource, and should not be copied, so making copy the identity is a safety measure. Examples: Semaphores, Mutexes, SharedQueues, data base connections, some kinds of streams, singletons. * Laziness or error (inherited method not revised). What is your use case? On Thu, 21 Feb 2019 at 07:32, Petr Fischer via Pharo-users < pharo-users@lists.pharo.org> wrote:
Hello, some classes, like Symbols or SmallIntegers, shares identity of value instances in the whole image (I may say it wrong), so:
1 == 1 copy. [true] #aaa == #aaa copy. [true]
all other classes not, like Strings, Objects etc., so:
'aaa' == 'aaa' copy. [false]
Is there any test method (maybe on the class side) I could ask for this (isXXX)?
Thanks! pf
It is not clear to me what the semantics of such a selector would be. Consider this example: t := [:x | x copy == x]. a := t value: 1.0e38. b := t value: 1.0e308. What do you expect a and b to be? GNU Smalltalk: a=true, b=true. My Smalltalk, 32-bit or 64-bit: a=true, b=true. Squeak/Pharo, 32-bit: a=false, b=false. Squeak/Pharo, 64-bit: a=true, b=false. Squeak/Pharo, after a patch: a=true, b=true.
There are two quite different reasons why x copy == x might be true: * x is immutable (including its parts), and can be thought of as a mathematical value, so that there is no need to copy it Examples: every kind of number, characters, booleans, immutable collections, block closures * x is a way of accessing a unique resource, and should not be copied, so making copy the identity is a safety measure. Examples: Semaphores, Mutexes, SharedQueues, data base connections, some kinds of streams, singletons. * Laziness or error (inherited method not revised).
What is your use case?
I see... My use case was too superficial - thanks for answer! pf
On Thu, 21 Feb 2019 at 07:32, Petr Fischer via Pharo-users < pharo-users@lists.pharo.org> wrote:
Hello, some classes, like Symbols or SmallIntegers, shares identity of value instances in the whole image (I may say it wrong), so:
1 == 1 copy. [true] #aaa == #aaa copy. [true]
all other classes not, like Strings, Objects etc., so:
'aaa' == 'aaa' copy. [false]
Is there any test method (maybe on the class side) I could ask for this (isXXX)?
Thanks! pf
participants (2)
-
Petr Fischer -
Richard O'Keefe