Metaprogramming in Squeak
In comp.lang.smalltalk today, I got to answer a simple question about metaprogramming. My classic example is being able to create an anonymous class simply by calling "Behavior New". Here's my code:
| myClass myInstance |
myClass := Behavior new. "create anon behavior"
myClass compile: 'theAnswer ^42'. "add a method for instances"
myInstance := myClass new. "create an instance"
Transcript show: myInstance theAnswer; cr. "shows 42"
Comments