logo       

Re: bags use: msg#00088

lang.smalltalk.squeak.beginners

Subject: Re: bags use

aBag := Bag new.
aBag add: ... add some of your objects.
aBag anySatisfy: [:each | (each name = 'aName') & (each status = 'good')]

assuming that your class has implemented instance methods #name, and #status.

#anySatisfy: will work with all collection types. You not need to use a Bag.

Also do not confuse Smalltalk terminology regarding identity and equality.
Identity comparisons #== always checks to see if the lhs and rhs
objects are the same object.

objectA == objectB -- is true if and only if objectA refers to the
same object as objectB.

Equality comparisons #=

objectA = objectB --tests to see if the two objects are equivalent.

If you want to perform equality tests between objects then define the
#= instance method for the objects class. You should also define
#hash.

See class Point for examples for implementing #= and #hash.


On 21/06/06, Benjamin SALLAS <benjamin.sallas@xxxxxxxxxx> wrote:
hello,
I'm trying to use bags correctly, and i need a little help.
I'd like to create a bag with some instance of a class with variables (for
example: name, status).
I'd like to make the identity of the bag on the name only, and be able in a
loop to get the status of each item.
With my example, the status is 'good' or 'bad', i want to check if one of the
item with a certain name has the status 'good'.
Could someone explain me how i can do that?

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



--
---
Edward Stow


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise