[Newbies] Total newb...
Tony Giaccone
tony at giaccone.org
Tue Oct 14 07:22:21 UTC 2008
Exactly Correct.
There exists a method on Set, with selector contains: which would on
first examination seem to be the right thing.
Set contains: object
but contains seems to take a Block not an object.
so perhaps includes does what I want?
Clearly this works
>> validHands anySatisfy: [ :elem | elem respondsTo: #throwsAHand ]
in that if the class has a that selector it would be correct.
But what I really was looking for is
Given a set, how do I determine
1) If an object is a member of he set.
2) How do I specify when two objects are equal? Is part of this.
Obviously two objects which have the same address which I think in
smalltalk is == operator are the same object..
but what if I want equality to be based on the value of some internal
class value.
Maybe I'm thinking too much like a java programmer.
Tony
On Oct 14, 2008, at 2:56 AM, Matthias Berth wrote:
> Hi Michael,
>
> I think Tonys model of the game is like this:
>
> A Player throws a hand. That can be any of "rock", "scissors", or
> "paper". Now someone (a Game object?) has to check if the player did
> not make a mistake, say by throwing a "well". The set of legal throws
> (in this game, anyway) is somehow defined by Tony. So the Game object
> checks if the throw is an element of the set of legal throws.
>
> Am I describing this correctly, Tony?
>
> Cheers
>
> Matthias
>
> On Tue, Oct 14, 2008 at 8:45 AM, Michael Haupt <mhaupt at gmail.com>
> wrote:
>> Hi Tony,
>>
>> On Tue, Oct 14, 2008 at 8:11 AM, Tony Giaccone <tony at giaccone.org>
>> wrote:
>>> validHands := Set new.
>>> validHands add: Rock new; add Paper new; add Scissors new.
>>>
>>> Assume I have a player object which responds to the method
>>> throwsAHand with
>>> an instance of Rock Paper or Scissors.
>>>
>>> how do I craft
>>>
>>> validHands contains: aPlayer throwsAHand
>>
>> 'ere, how about this:
>>
>> validHands anySatisfy: [ :elem | elem respondsTo: #throwsAHand ]
>>
>> Collection >> #anySatisfy: takes a block and evaluates it for all the
>> elements in the collection. It returns true if the block evaluates to
>> true for any of the elements, and false otherwise.
>>
>> Object >> #respondsTo: accepts a symbol (!) denoting a message name
>> and returns true if the object in question understands that message.
>>
>> Did I make clear what the above code does?
>>
>> Best,
>>
>> Michael
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
More information about the Beginners
mailing list