meta-level programming examples 
Author Message
 meta-level programming examples

Can anyone point out some examples of Smalltalk meta-level programming.  I'm
looking for stuff like building a class from scratch (through code, not the
IDE) or building an object and then assigning the class, etc.  (BTW- I'm
normally a Java guy, but I think I could try out some concepts quicker in
Smalltalk.)

Thank for any help!
Garrett Snider



Tue, 12 Aug 2003 05:29:14 GMT  
 meta-level programming examples
If you use VW:

to create a class TestClass:

Object subclass: 'TestClass'
        instanceVariableNames: 'i1 i2'
        classVariableNames: 'C1 C2'
        poolDictionaries: ''
        category: 'Test'

to add a protocol to class TestClass:

TestClass organization addCategory: #aProtocol

to add a method to class TestClass:

TestClass compile: #method
                classified: #aProtocol

Guang Yang


Quote:
> Can anyone point out some examples of Smalltalk meta-level programming.
I'm
> looking for stuff like building a class from scratch (through code, not
the
> IDE) or building an object and then assigning the class, etc.  (BTW- I'm
> normally a Java guy, but I think I could try out some concepts quicker in
> Smalltalk.)

> Thank for any help!
> Garrett Snider



Tue, 12 Aug 2003 05:55:10 GMT  
 meta-level programming examples
The text pane in the browser is just a handy little editor for composing
the code to build a class.  In other words, what you see in the browser
is what you are looking for.  Launch any Smalltalk and just look at it's
class browser and try to create a subclass with the class browser and
you will be presented with the code.  The browser will present it to you
like as if it is a template for you to fill out, but never-the-less, it
*is* the actual code that you would use.

Here it is from a VW 3.0 browser:

NameOfSuperclass subclass: #NameOfClass
        instanceVariableNames: 'instVarName1 instVarName2'
        classVariableNames: 'ClassVarName1 ClassVarName2'
        poolDictionaries: ''
        category: 'SomeCategoryName'

And here it is from a VA browser:

Object subclass: #MyClass1
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''

When the programmer sends the above message, the new class is created on
the fly.  The fact that the message was sent from a browser is
irrelevant.  The same code words regardless of from where it is sent.

Quote:

> Can anyone point out some examples of Smalltalk meta-level programming.  I'm
> looking for stuff like building a class from scratch (through code, not the
> IDE) or building an object and then assigning the class, etc.  (BTW- I'm
> normally a Java guy, but I think I could try out some concepts quicker in
> Smalltalk.)

> Thank for any help!
> Garrett Snider

So far as "building an object and then assigning the class", please note
that ALL objects are instances of some class.  You cannot build an
object that is NOT already an instance of some class.  Therefore, the
only possible interpretation that I can think of for your request is to
"build an object and then change the class".  You can do that with
#become:, or #changeClassTo:, or any one of several variations:

myClass1Instance changeClassTo: MyClass2

Nevin Pratt



Tue, 12 Aug 2003 11:06:45 GMT  
 meta-level programming examples
Hi Nevin,
  Yes, I realized this was the case (and slapped myself in the forehead)
when I saw Guang's reply.  It's a bit hard to internalize that everything in
the system is an object.

Thanks for the help.

(To all readers: I'm still hoping that people will point out articles, etc
on meta-level programming in Smalltalk)

-garrett


Quote:
> The text pane in the browser is just a handy little editor for composing
> the code to build a class.  In other words, what you see in the browser
> is what you are looking for.  Launch any Smalltalk and just look at it's
> class browser and try to create a subclass with the class browser and
> you will be presented with the code.  The browser will present it to you
> like as if it is a template for you to fill out, but never-the-less, it
> *is* the actual code that you would use.

> Here it is from a VW 3.0 browser:

> NameOfSuperclass subclass: #NameOfClass
> instanceVariableNames: 'instVarName1 instVarName2'
> classVariableNames: 'ClassVarName1 ClassVarName2'
> poolDictionaries: ''
> category: 'SomeCategoryName'

> And here it is from a VA browser:

> Object subclass: #MyClass1
>     instanceVariableNames: ''
>     classVariableNames: ''
>     poolDictionaries: ''

> When the programmer sends the above message, the new class is created on
> the fly.  The fact that the message was sent from a browser is
> irrelevant.  The same code words regardless of from where it is sent.


> > Can anyone point out some examples of Smalltalk meta-level programming.
I'm
> > looking for stuff like building a class from scratch (through code, not
the
> > IDE) or building an object and then assigning the class, etc.  (BTW- I'm
> > normally a Java guy, but I think I could try out some concepts quicker
in
> > Smalltalk.)

> > Thank for any help!
> > Garrett Snider

> So far as "building an object and then assigning the class", please note
> that ALL objects are instances of some class.  You cannot build an
> object that is NOT already an instance of some class.  Therefore, the
> only possible interpretation that I can think of for your request is to
> "build an object and then change the class".  You can do that with
> #become:, or #changeClassTo:, or any one of several variations:

> myClass1Instance changeClassTo: MyClass2

> Nevin Pratt



Tue, 12 Aug 2003 20:48:07 GMT  
 meta-level programming examples

Quote:
> ...
> (To all readers: I'm still hoping that people will point out articles, etc
> on meta-level programming in Smalltalk)

Hi Garrett,
I suggest you take a look at the following:

Smalltalk: a Reflective Language
    http://www.parc.xerox.com/csl/groups/sda/projects/reflection96/docs/r...

Brian Foote has tons of staff at:
    http://www.laputan.org/foote/papers.html#Reflection
(especially: Reflective Facilities in Smalltalk-80 & Reflective Programming in Smalltalk)

Metaclass extensions and languages built on them
    http://brain.cs.uiuc.edu/VisualWorks/Metaclass+extensions+and+languag...

the Refactoring Brwoser uses meta programming extensively. try following the code.
    http://st-www.cs.uiuc.edu/~brant/RefactoringBrowser/

lastly, my SmallInterfaces has plenty of meta programming examples.
what might be specially helpful for you is that I have tried to make it very readable; plenty of comments and "self-documenting" code.
    http://brain.cs.uiuc.edu/VisualWorks/SmallInterfaces

happy reading,
Benny Sadeh



Wed, 13 Aug 2003 01:03:38 GMT  
 meta-level programming examples

Quote:

> (To all readers: I'm still hoping that people will point out articles, etc
> on meta-level programming in Smalltalk)

By this I think you mean you would like to see examples, articles, etc.,
of invoking behavior (ie, invoking methods) that would be classified as
meta-behavior.  Such methods I will term "meta-methods".  Probably the
best examples of these would be the behaviors invoked by the IDE
itself.  And, any articles written about IDE enhancements would likely
be dealing with meta-behaviors as well.

A comment I made on CLS many months ago (and got beat up for it) was
that it is sometimes difficult to look at a method and say "yes, that is
a meta-method", or "no, this one is not a meta-method".  While the
*concepts* of meta and non-meta might be non-ambiguous, the neat
classification of exactly which methods are meta and which are not is
often ambiguous.  Part of this is because the actual dividing line
depends on your context.  I know that I could not come up with a
succinct and exhaustive list of methods whose behavior would generally
be classified as meta-behavior, and I seriously doubt anybody else could
either (at least, not a list that wouldn't provoke widespread
controversy).

Nevin Pratt



Wed, 13 Aug 2003 01:05:53 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. IMSA'92 Workshop on Reflection and Meta-Level Architectures

2. IMSA'92 Workshop on Reflection and Meta-Level Architectures

3. IMSA'92 Workshop on Reflection and Meta-Level Architectures

4. META88 -- Workshop on Meta-Programming in Logic Programming

5. BlackBox Meta: accessing methods through Meta

6. meta-circular-meta-interpreters (long)

7. #\Meta #\Control #\Meta-Control etc.

8. Ann: Article: Line-labelling by meta-programming

9. need good reference for meta-programming

10. meta-programming, strong typing, and monads

11. Meta-programming question

12. FW: [PHP Classes] MetaL - a XML based meta-programming language developed using PHP

 

 
Powered by phpBB® Forum Software