Issues creating instance of SmallInteger

Colin Putney cputney at wiresong.ca
Fri May 12 16:17:32 UTC 2006


On May 12, 2006, at 11:32 AM, Michel Calonne wrote:

> Hello,
> I've got a problem creating objects via this sample of code:
> (Smalltalk at: #AClassName) new
> The problem is that, when trying to create an instance of  
> SmallInteger, it raises an error :
> "SmallIntegers can only be created by performing arithmetic"...
> If somebody can tell me why it isn't possible to create a  
> SmallInteger like this, and give me a way to do it, I'd appreciate...
> And are there other classes behaving the same way? So that I can  
> take them in account in my code.

My guess is that #new is forbidden to SmallIntegers because it's an  
immediate - you can't just create an object with all it's instance  
variables set to nil. For a SmallInteger to exist it must have a  
specific integer value.

On the other hand, throwing an error doesn't seem like useful  
behavior, either. Changing the definition of #new to just return 0  
would be perfectly reasonable. Heck, it could return 7 for that matter.

Colin



More information about the Squeak-dev mailing list