[Q] Class definition

Eric Arseneau eat at huv.com
Wed Jun 28 17:40:12 UTC 2000


If you look at the method
ClassBuilder>>#name:inEnvironment:subclassOf:type:instanceVariableNames:clas
sVariableNames:poolDictionaries:category:unsafe:

The first line or so calls
	instVars _ Scanner new scanFieldNames: instVarString.

You could change this line to extract the type info and store it somewhere
else, and extract the names of the inst vars and keep those for the class
builder.

If you call
	Scanner new scanFieldNames:
with the argument you passed in the expression below, you can debug what
happens.

You could also use a syntax already supported by Smalltalk's like Visual
Works

	instanceVariables: 'i <Integer> j <Integer> c <Character>'

And replace the same code above and pullout the type info.  The plus side
for this is that you can use it for method headers as well:

	print: stream <WriteStream> indent: indent <Integer>

I don't remember whether the Squeak parser handles this directly, but I do
know that the old ST-80 parser had a flag in the parser to indicate whether
it should parse type information or not.  Just don't remember what version.

> Hi!
>
> Is there a good reason why class definitions are not handled as source
> code?
>
> It is not possible to put comments there and not possible to change the
> layout of things. This is not an idle question as I intend to try out
> some ideas that needs type information to be stored with the instance
> variables.
>
> The following for example will be parsed and useful with normal ST-80
> syntax, at the same time it can be read as having types associated with
> the variables. I will present a version of this later this year
> as an alternative
> to the present Slang.
>
> Object subclass: #X
> 	instanceVariableNames:
> 		#(":int" i j
> 		  ":char" c)
> 	classVariableNames: ''
> 	poolDictionaries: ''
> 	category: ''
>
> The compiler (or whoever) changes it to
>
> Object subclass: #X
> 	instanceVariableNames: 'i j c '
> 	classVariableNames: ''
> 	poolDictionaries: ''
> 	category: ''
>
> Perhaps a new field could be added to ClassDescription for the
> source code?
> That would also make it easier to document the variables, write a short
> comment when it is introduced.
>
> Adding a field to all classes and metaclasses, is that very difficult?
>
> /Mats
>
>





More information about the Squeak-dev mailing list