[Q] Enum style Object?

Hannes Hirzel hannes.hirzel.squeaklist at bluewin.ch
Wed Feb 19 07:06:11 UTC 2003

Brian T Rice <water at tunes.org> wrote:
> On Tue, 18 Feb 2003, Eric Merritt wrote:
> > This question probably has an obvious solution but I
> > can't see it at the moment.
> >
> > For the most part my Java experience has proved to be
> > useful in aqueak (squeak is like the garden of eden
> > compared to java :) but I am having trouble getting my
> > mind around a state machine. In java I would just
> > create a state instance var thats a byte and tehn have
> > a series of static final bytes that represent each
> > state, in C/C++ I would use an enum. I can't, however,
> > for the life of me figure out how to translate this to
> > squeak. I guess maybe the states  would be class vars
> > initialized  in the class initializer but this seems a
> > bit strange to me. Would one of you point me in the
> > right direction?
> You can use symbols (for example, #stateOne #stopped #end) and compare
> them with ==, which is pretty fast and lightweight.
Yes and you may have a class variable containing a dictionary 
which map states to subdictionaries. The subdictionaries contain
as the key  input symbols and the values are nextSymbol -
outputSymbol associations. So you can have huge state charts
stored in a space efficient way.

Perhaps it is easier to explain if you provide some code
or a specific example.

Hannes Hirzel

More information about the Squeak-dev mailing list