[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squeak-beginners
Subject:    Re: [Newbies] reimplementing #= and #hash
From:       "Ching de la Serna" <ching.dls () gmail ! com>
Date:       2007-09-24 0:40:13
Message-ID: 29b6524b0709231740l100b0860id97c564259d53107 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Janko,

Thanks for your help. Your code makes it clear.

Ching

On 9/23/07, Janko Mivšek <janko.mivsek@eranova.si> wrote:
>
> Hi Ching,
>
> #= is test for equality while #== is test for identity. What do you
> probably want is to override #= to compare two PoolQueues if they are
> equal or not. But what "equal" means in your case is on you to define.
> Maybe something like this:
>
> PoolQueue>>= anotherPoolQueue
>
>    ^(self member = anotherPoolQueue member)
>         and: [self processor = anotherPoolQueue member]
>
> But be sure that also member and processor instvars understand #= in a
> correct way. All numbers, strings, symbols etc. understand equality as
> expected.
>
> I hope this helps a bit.
> Janko
>
>
> Ching de la Serna wrote:
> > Hi List,
> >
> > I have a Class PoolQueue which has instvars 'member' and 'processor'. I
> > find that an instance of PoolQueue when placed in an OrderedCollection
> > can no longer be considered equal. I suppose I have to reimplement #=
> > and #hash to allow PoolQueue instances to be compared.
> >
> > My problem: how do I implement #hash? Or stated another way, what does
> > #hash accomplish?
> >
> > Thanks in advance.
> >
> > Ching.
> >
>
> --
> Janko Mivšek
> AIDA/Web
> Smalltalk Web Application Server
> http://www.aidaweb.si
> _______________________________________________
> Beginners mailing list
> Beginners@lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

[Attachment #5 (text/html)]

Hi Janko,<br><br>Thanks for your help. Your code makes it \
clear.<br><br>Ching<br><br><div><span class="gmail_quote">On 9/23/07, <b \
class="gmail_sendername">Janko Mivšek</b> &lt;<a \
href="mailto:janko.mivsek@eranova.si">janko.mivsek@eranova.si </a>&gt; \
wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, \
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Ching,<br><br>#= is test \
for equality while #== is test for identity. What do you <br>probably want is to \
override #= to compare two PoolQueues if they are<br>equal or not. But what \
&quot;equal&quot; means in your case is on you to define.<br>Maybe something like \
this:<br><br>PoolQueue&gt;&gt;= anotherPoolQueue <br><br>&nbsp;&nbsp; ^(self member = \
anotherPoolQueue member)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and: \
[self processor = anotherPoolQueue member]<br><br>But be sure that also member and \
processor instvars understand #= in a<br>correct way. All numbers, strings, symbols \
etc. understand equality as <br>expected.<br><br>I hope this helps a \
bit.<br>Janko<br><br><br>Ching de la Serna wrote:<br>&gt; Hi List,<br>&gt;<br>&gt; I \
have a Class PoolQueue which has instvars &#39;member&#39; and &#39;processor&#39;. \
I<br>&gt; find that an instance of PoolQueue when placed in an OrderedCollection \
<br>&gt; can no longer be considered equal. I suppose I have to reimplement \
#=<br>&gt; and #hash to allow PoolQueue instances to be compared.<br>&gt;<br>&gt; My \
problem: how do I implement #hash? Or stated another way, what does <br>&gt; #hash \
accomplish?<br>&gt;<br>&gt; Thanks in advance.<br>&gt;<br>&gt; \
Ching.<br>&gt;<br><br>--<br>Janko Mivšek<br>AIDA/Web<br>Smalltalk Web Application \
Server<br><a href="http://www.aidaweb.si">http://www.aidaweb.si \
</a><br>_______________________________________________<br>Beginners mailing \
list<br><a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br><a \
href="http://lists.squeakfoundation.org/mailman/listinfo/beginners"> \
http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br></blockquote></div><br>




_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic