Login  Register

Re: What's the correct way to create anonymous subclasses in Pharo?

Posted by Stéphane Ducasse on Jun 21, 2010; 1:32pm
URL: https://forum.world.st/What-s-the-correct-way-to-create-anonymous-subclasses-in-Pharo-tp2227809p2262647.html

can you enter a bug entry in the bug report?

Stef

On May 23, 2010, at 2:49 PM, Joachim Geidel wrote:

> Hi everybody,
>
> I am attempting to create subclasses of existing classes at runtime. They
> must not be in their superclass' list of subclasses, because they have to be
> garbage collected when they are no longer needed.
>
> This is what I tried to create such a class in Pharo 1.0:
>
>    newMeta := (Metaclass new)
>        superclass: Rectangle class
>            methodDictionary: MethodDictionary new
>            format: Rectangle class format;
>        yourself.
>    newClass := (newMeta new)
>        superclass: Rectangle
>            methodDictionary: MethodDictionary new
>            format: Rectangle format;
>        setName: #MyRectangle;
>        yourself.
>    newClass new class == newClass  "--> false"
>
> The result of "newClass new" seems to be an instance of Rectangle, not of
> newClass. The test at the end of the code snippet answers false. When I
> compile a new method in newClass and install it in newClass'
> methodDictionary, an instance will not understand a message with the
> method's selector.
>
> Almost the same code will do what I want in VisualWorks:
>
> | newMeta newClass |
>   newMeta := (Metaclass new)
>        superclass: Rectangle class;
>        methodDictionary: MethodDictionary new;
>        setInstanceFormat: Rectangle class format;
>        yourself.
>    newClass := (newMeta new)
>        superclass: Rectangle;
>        methodDictionary: MethodDictionary new;
>        setInstanceFormat: Rectangle format;
>        setName: #MyRectangle;
>        yourself.
>    newClass new class == newClass  "--> true"
>
> Does anybody have an idea what the problem is and what can be done to
> circumvent it?
>
> Thanks in advance!
> Joachim Geidel
>
>
>
> _______________________________________________
> Pharo-users mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users