Implementing a "prototype" in Squeak

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing a "prototype" in Squeak

Miso
Hi, I'm trying to creating a concept similar to "prototype" (like prototype-oriented programming) in Squeak. What I want is an object's methodDictionary to be stored in itself. So when I send a message to an instance, Squeakshould look in the instance's dictionary (as opposed to class' dictionary) and call method stored there.

Closest thing I managed to do was create an anonymous class (subclass on my custom class) for each instance and return instance of this class, and store the anonymous class in the instance so I can work with it. Is there any other way to do it, without modifying compiler/VM or writing custom compiler? If not, please give some pointers where to look for some information about "core" of Squeak.

Thanks
Michael
Reply | Threaded
Open this post in threaded view
|

Re: Implementing a "prototype" in Squeak

Randal L. Schwartz
>>>>> "Miso" == Miso  <[hidden email]> writes:

Miso> Hi, I'm trying to creating a concept similar to "prototype" (like
Miso> prototype-oriented programming) in Squeak. What I want is an
Miso> object's methodDictionary to be stored in itself. So when I send a
Miso> message to an instance, Squeakshould look in the instance's
Miso> dictionary (as opposed to class' dictionary) and call method
Miso> stored there.

Miso> Closest thing I managed to do was create an anonymous class
Miso> (subclass on my custom class) for each instance and return
Miso> instance of this class, and store the anonymous class in the
Miso> instance so I can work with it. Is there any other way to do it,
Miso> without modifying compiler/VM or writing custom compiler? If not,
Miso> please give some pointers where to look for some information about
Miso> "core" of Squeak.

One of the responses to my thread about anon classes at

  http://methodsandmessages.vox.com/library/post/metaprogramming-in-squeak.html

brings up an oroboros, which is esssentially what you're looking for.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: Implementing a "prototype" in Squeak

Ralph Johnson
"Behavior" is what the VM knows about classes.  You shouldn't add instance variables to Behavior, but you can add them to Class or Metaclass, which are derived from it.

The trick of making an instance of Behavior that is a subclass of your class, and then making that instance your class, is often called "Lightweight classes".  I think it is just as good as giving your object a method dictionary.  It is amusing to make an object be its own class, but I don't see the advantage.  Most of the time you do not want your inspector to show the method dictionary.

-Ralph


Reply | Threaded
Open this post in threaded view
|

Re: Implementing a "prototype" in Squeak

Chris Muller-3
In reply to this post by Miso
Yes, you could work WriteBarrier to dynamically generate override
methods in an anonymous subclass.

Also, you might try Googling for "mixins".  I think there was a
Smaltalk impl. of mixins a long time ago..

On Sat, Apr 24, 2010 at 10:07 AM, Miso <[hidden email]> wrote:

>
> Hi, I'm trying to creating a concept similar to "prototype" (like
> prototype-oriented programming) in Squeak. What I want is an object's
> methodDictionary to be stored in itself. So when I send a message to an
> instance, Squeakshould look in the instance's dictionary (as opposed to
> class' dictionary) and call method stored there.
>
> Closest thing I managed to do was create an anonymous class (subclass on my
> custom class) for each instance and return instance of this class, and store
> the anonymous class in the instance so I can work with it. Is there any
> other way to do it, without modifying compiler/VM or writing custom
> compiler? If not, please give some pointers where to look for some
> information about "core" of Squeak.
>
> Thanks
> Michael
> --
> View this message in context: http://forum.world.st/Implementing-a-prototype-in-Squeak-tp2063564p2063564.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>
>