[squeak-dev] SmallInteger someInstance == nil :(

Florin Mateoc florin.mateoc at gmail.com
Tue Jul 21 16:10:44 UTC 2020

First off, apologies for top-posting, fixed below, with some additional

On Tue, Jul 21, 2020 at 11:56 AM Florin Mateoc <florin.mateoc at gmail.com>

> On Tue, Jul 21, 2020 at 9:21 AM Fabio Niephaus <lists at fniephaus.com>
> wrote:
>> On Tue, Jul 21, 2020 at 3:08 PM Marcel Taeumel <marcel.taeumel at hpi.de>
>> wrote:
>>> Maybe I can check for #isImmediateClass first :-)
>> That's a good idea. Note that primitiveSomeInstance also returns nil in
>> case no instance exists (e.g. `EToyProjectDetailsMorph someInstance ==
>> nil`).
>> I believe the behavior you observe wrt immediates has historical reasons:
>> #someInstance returns the first instance found in the object memory, and
>> you can use #nextInstance: for iteration (this mechanism was later replaced
>> by #allInstances). Iterating instances doesn't make sense for immediates,
>> the "same instance" can occur multiple times in the heap.
>> Fabio

Actually, primitiveSomeInstance fails, it does not return nil. It is the
image-side primitive failure code that returns nil.
Which brings us to the question: why not fix it in Smalltalk, if you think
the behavior (as implemented in Behavior :)) is not appropriate for
immediate classes?
If you override the method in the immediate classes and replace the
primitive failure code with something more appropriate for each immediate
class, you can have them return good exemplars

Also note that, as Eliot said, nextInstance does not make sense for
immediate classes. This implies that someInstance does not make sense
either when thought of as the dual of nextInstace (which it is, in many
But I think someInstance can make sense on its own, as in your scenario,
that is the context in which I proposed to "fix it"


> Am 21.07.2020 15:07:01 schrieb Marcel Taeumel <marcel.taeumel at hpi.de>:
>>> Hi Fabio.
>>> From an object-oriented perspective, it would be nice to get "some
>>> instance" when asking a class in the system for #someInstance. :-)
>>> As it is now, I have to start writing a little lookup table with "class
>>> == SmallInteger ifTrue: [ .... ]" to lookup exemplary instances for some
>>> classes in the system.
>>> Best,
>>> Marcel
>>> Am 21.07.2020 14:53:31 schrieb Fabio Niephaus <lists at fniephaus.com>:
>>> On Tue, Jul 21, 2020 at 2:24 PM Marcel Taeumel <marcel.taeumel at hpi.de>
>>> wrote:
>>>> Hi all!
>>>> Why is "SmallInteger someInstance == nil"?
>>> Because SmallIntegers are immediate and cannot be instantiated
>>> (`SmallInteger new` fails). This implies:
>>> "SmallFloat64 someInstance == nil"
>>> "Character someInstance == nil"
>>> Why would you want someInstance of SmallInteger anyway?
>>> Fabio
>>>> Best,
>>>> Marcel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200721/73db9b44/attachment.html>

More information about the Squeak-dev mailing list