In general, I avoid code generation as much as possible, but it is
fairly easy in Squeak. The text you see in a browser when you define
a new subclass is, in fact, an executable statement that sends a
message to a class to create a subclass. IOW:
Set subclass: #Dictionary
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Collections-Unordered'
sends a message to Set to create a subclass called Dictionary.
To add methods, you can ask the class to compile a string - basically
the same string you see in the browser. Look at
Behavior>>compile:notifying:
If you dig around Class, Behavior, MetaClass, and similar, you'll
find all sorts of nifty meta manipulation goodies for removing
methods, fiddling with ivars, etc.
On Jul 30, 2006, at 4:25 PM, Keith R. Fieldhouse wrote:
> Hello,
>
> For a project I have in mind, I'd like to do some in-image code
> generation. I actually do this quite a bit in other languages for
> one reason and another but it seems as though it'd be a somewhat
> different beast inside a Squeak image.
>
> So, of the various packages available on SqueakMap/SqueakSource/
> Monticello is there one that you'd consider a good example of code
> generation techniques with Squeak? Or is there something already
> in the image that's worth looking at? I'm interested in generating
> new classes and methods on both sides. Something that uses some
> sort of templating facility would be interesting as well.
>
> Thanks for your help,
>
> Keith
>