[Newbies] Smalltalk is a Mystery to Me

Marcin Tustin mm3 at zepler.net
Fri Aug 22 22:51:52 UTC 2008


On Fri, Aug 22, 2008 at 1:30 AM, <Tcykgreis at aol.com> wrote:

>  I have had a curiosity about Smalltalk for many years so I recently
> downloaded and installed Squeak. That's when the trouble began. I have
> written applications that deal bridge hands and either display the hands on
> screen or save them in a couple of different formats. I originally wrote the
> 'words' in Forth. I later tried Ruby and rewrote most of the programs in
> Ruby. I did it as a learning experience. I sat out to do the same thing in
> Squeak, again as a learning experience, but have made virtually no progress.
> I create the class 'Bridge' with the subclass of dealer. I try to initialize
> by filling a byteArray with 52 numbers, 0 through 51.
>

Woah...what? This doesn't really make any sense.


> I tended to create additional methods to shuffle and deal the cards to four
> more byte arrays named north, east, south, and west. Eventually I will need
> another method to "stack the deck." I will also need a counter to keep track
> of the deal number.
>
> I can't get started, and I mean zero progress, because I can't create and
> load deck. It seems like the documentation is never quit up to date. I read
> about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept
> it, first deck is questioned and then after deck I get something about not
> expecting anything else.
>

This is because deck is undeclared, and then because you have a syntax
error.


> I know there is a word 'asByteArray:' and I assume a number would specify
> the size of the array but nowhere can I find anything about the order in
> which the information should be provided. I tried deck asByteArray: 52 but I
> don't know if it worked. If it did work, how do I load the bytes into it?
> How do I look at a byte in a particular location in the array? Can I remove
> a byte from position x and/or insert a byte at position y and everything
> moves to accommodate the change.
>

First of all, are you familiar with the syntax?

Squeak by example will help guide you through looking at classes, and seeing
what methods they have etc.

>
> In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits
> and 13 bits. If the card was present the bit was set. When I dealt the
> cards, the appropriate bits were set.. This worked really well. The suits
> came out already sorted. The strength of a suit turned out to be related to
> the value stored for the suit. The number of cards in the suit could be
> found by counting set bits. I have yet to find bit-manipulating words in
> Squeak/Smalltalk.
>
> As an aside, the least number of bits that must be used to store a complete
> deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The
> position in the array represents the value of the card and the bits
> determine which hands gets the card represented by that position. When you
> shuffle the 2-bit groups must be kept in tact. I could easily do this in
> Forth but could not do it in Ruby. If you are going to save a few million
> hands, it is nice to be able to do so in this most compact form.
>
> If I could just figure out where to find the answers to these beginner
> question, I would really appreciate it. It would also be nice if I could see
> some examples of these methods.
>
> Charlie
>
>

I would recommend that you create a card class, with a member variable that
represents the suit (probably as a symbol) and a second member variable that
represents the card in the suit. Create a class method that returns new
instances (eventually have it throw an exception if something out of the
range of what is acceptable is created) and have a second class method that
creates a collection of cards that contains all the cards, in order. You can
use the methods on the appropriate collection to shuffle it.

Once you've built something working on that, you can try to optimise
storage, either on disk or in memory.


>
>
>
> ------------------------------
> It's only a deal if it's where *you* want to go. Find your travel deal *
> here* <http://information.travel.aol.com/deals?ncid=aoltrv00050000000047>.
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080822/0352d6d3/attachment.htm


More information about the Beginners mailing list