Unique objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Unique objects

Fernando Rodríguez
Hi,

Besides symbols, what other objects are garanteed to be unique? Is
this common to all smaltalks?

Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Unique objects

Günther Schmidt
Fernando wrote:
> Hi,
>
> Besides symbols, what other objects are garanteed to be unique? Is
> this common to all smaltalks?
>
> Thanks

Characters, SmallIntegers ....


Reply | Threaded
Open this post in threaded view
|

Re: Unique objects

Steven Kelly
"Günther Schmidt" <[hidden email]> wrote in message news:425e8ed6$[hidden email]...
> Fernando wrote:
>> Besides symbols, what other objects are garanteed to be unique? Is
>> this common to all smaltalks?
>
> Characters, SmallIntegers ....

true, false, nil
i.e. singleton instances of True, False and UndefinedObject.

'uniqueness' here clearly means different things in different cases, may be handled in different ways, and there may be
ways of circumventing it. But don't try that at home :-).

Symbols aren't actually very strongly unique in VW: try
Symbol new == Symbol new.

Offhand, I can't think of another base class like Symbol, whose potential set of instances is countably infinite, but
for which it is guaranteed (other than tricks like the above) that no two instances are = unless they are also ==.

Steve


Reply | Threaded
Open this post in threaded view
|

Re: Unique objects

Chris Uppal-3
Steven Kelly wrote:

> Offhand, I can't think of another base class like Symbol, whose potential
> set of instances is countably infinite, but for which it is guaranteed
> (other than tricks like the above) that no two instances are = unless
> they are also ==.

How about Object ?

;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Unique objects

Steven Kelly
"Chris Uppal" <[hidden email]> wrote in message
news:425e9b69$0$38044$[hidden email]...
> Steven Kelly wrote:
>
>> Offhand, I can't think of another base class like Symbol, whose potential
>> set of instances is countably infinite, but for which it is guaranteed
>> (other than tricks like the above) that no two instances are = unless
>> they are also ==.
>
> How about Object ? ;-)

Depends what you mean. The OP and I were talking about cases like Symbol, for which:
('ab', 'cd') asSymbol == ('ab', 'cd') asSymbol
whereas for Strings:
('ab', 'cd') ~~ ('ab', 'cd')

Object doesn't preserve uniqueness in this kind of way:
Object new ~~ Object new
which was perhaps the main point.

But of course you're right that I expressed myself unclearly when trying to pin uniqueness down to instances being = and
==, since
Object new ~= Object new
i.e. Object>>= simply uses ==.

But then since this is Smalltalk, I could read your mention of Object as meaning an instance, rather than a class: try
Object class new == Object class new
and you'll see Smalltalk maintaining Object as the singleton instance of the Metaclass instance "Object class".

We can however happily do:
Object class basicNew
to get a new "Object" clone. Unfortunately, having skipped most of the important tying up of loose ends that class
creation normally does, we can't really use it as is to create new instances:
Object class basicNew new "DON'T TRY THIS!!'
will cause the VM to halt because somebody not only didn't understand a message, but didn't even understand
doesNotUnderstand:. And if I don't even understand what it is that I don't understand, I'm pretty stupid!

Steve