Case-logic/enumerated types

lex at cc.gatech.edu lex at cc.gatech.edu
Sun Oct 31 17:47:06 UTC 2004


> > An issue with enumerated types is that they are hard to extend.  What if
> > you make a subclass, and want to have an extra choice available in the
> > enumerated type?  With raw symbols this is fine.  With class-per-state
> > this is fine.  But with a Pascal-like or C-like (or ML-like!) enumerated
> > type, you can only extend it by editing the original definition.
> 
> I feel like saying "And this is =my= problem somehow?" but:
> 
> -> I would be happy just to have it private to a class.
> 
> -> If it were exposed, why would extending it be so challenging? They're  
> just integers underneath, eh? I guess there'd be some issues with passing  
> an enumerated type. Hmmm.
> 

I meant in Pascal or C.  In these languages, there is a single
declaration that lists all the possibilities.  To add more possibilities
you have to modify that declaration.  These languages don't have
subclasses, so it is not a big deal.  I wonder what C++ does for this,
though?  Can a C++ subclass add items to an enumerated type its
superclass uses?  I bet not -- figuring out what it would mean is a
headache!

In a Smalltalk (or Java) enumerated type, there's no declaration at all.
 You are right that you can just use more codes whenever and wherever
you like.


> > Chuck is good at finding all the symbols that are available in an
> > enumerated type.  Point to a variable which holds the Squeak equivelant
> > of an enumerated type, and, if Chuck can figure out what the code is
> > doing, the type of that variable will be the list of possible symbols.
> 
> What is Chuck? What is the Squeak-equivalent of an enumerated type?

Chuck is a project to help people browse Smalltalk code.  Its browser
lets you point to a variable and say "what is your type", among other
things.  The type system of Chuck includes types like "#foo or #bar or
#baz", ie lists of symbols.  And that's my answer to your second
question: I think that lists of symbols would be the Squeak-equivalent
of an enumerated type.

Chuck is on SqueakMap, and has this home page:

	http://www.cc.gatech.edu/~lex/chuck/

-Lex



More information about the Squeak-dev mailing list