Hello all,
I want to make an anonymous subclass, or a copy of (either way) a subclass of Object. I've been googling around looking for an example of an anonymous subclass. I haven't had luck with anything I've found. It's possible that there's something I'm missing conceptually, because I've read through various examples, but they all seem to do directly with Behavior or Class. I tried various combinations of things with both of the approaches I found. Some of them hung the image, with others the #primitiveChangeClassTo: would fail. I read the comment there, and am aware that using it is reckless behavior.
I see that Smalltalk compactClassesArray gives me a list of the compact classes. I don't seem to understand the format part. I've noticed that certain classes (e.g. Array) are declared "variable subclasses" but that's it. I googled and didn't turn up anything that seemed to help me grok it.
Tried: Class format. "answers 148" Head scratch; think. ^self shrug Any pointers?
-- Casey Ransberger _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
The usual reason for wanting that is to give a single object some special behavior. You end up with one class per object. That's why in Squeak we call them "uniclasses" and searching for selectors with "uniclass" should get you started.
- Bert - Am 18.12.2010 um 04:48 schrieb Casey Ransberger <[hidden email]>: > Hello all, > > I want to make an anonymous subclass, or a copy of (either way) a subclass of Object. > > I've been googling around looking for an example of an anonymous subclass. I haven't had luck with anything I've found. It's possible that there's something I'm missing conceptually, because I've read through various examples, but they all seem to do directly with Behavior or Class. I tried various combinations of things with both of the approaches I found. Some of them hung the image, with others the #primitiveChangeClassTo: would fail. I read the comment there, and am aware that using it is reckless behavior. > > I see that Smalltalk compactClassesArray gives me a list of the compact classes. I don't seem to understand the format part. I've noticed that certain classes (e.g. Array) are declared "variable subclasses" but that's it. I googled and didn't turn up anything that seemed to help me grok it. > > Tried: > > Class format. "answers 148" Head scratch; think. ^self shrug > > Any pointers? > -- > Casey Ransberger > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Ooh, so *that's* what a uniclass is. I'd seen references to them before and wondered what they were about. I will be searching my image for that in a moment:) I actually wanted to do two things. The anon subclass was about a test I was writing. And I was also fishing around looking for prototypes:)
On Fri, Dec 17, 2010 at 8:02 PM, Bert Freudenberg <[hidden email]> wrote: The usual reason for wanting that is to give a single object some special behavior. You end up with one class per object. That's why in Squeak we call them "uniclasses" and searching for selectors with "uniclass" should get you started. -- Casey Ransberger _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Casey Ransberger-2
Hi Casey,
Can you comment what's your use case for anonymous subclass? Or maybe post some example/testing code? Cheers, 2010/12/18 Casey Ransberger <[hidden email]>: > Hello all, > I want to make an anonymous subclass, or a copy of (either way) a subclass > of Object. > I've been googling around looking for an example of an anonymous subclass. I > haven't had luck with anything I've found. It's possible that there's > something I'm missing conceptually, because I've read through various > examples, but they all seem to do directly with Behavior or Class. I tried > various combinations of things with both of the approaches I found. Some of > them hung the image, with others the #primitiveChangeClassTo: would fail. I > read the comment there, and am aware that using it is reckless behavior. > I see that Smalltalk compactClassesArray gives me a list of the compact > classes. I don't seem to understand the format part. I've noticed that > certain classes (e.g. Array) are declared "variable subclasses" but that's > it. I googled and didn't turn up anything that seemed to help me grok it. > Tried: > Class format. "answers 148" Head scratch; think. ^self shrug > Any pointers? > -- > Casey Ransberger > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > -- Hernán Morales Information Technology Manager, Institute of Veterinary Genetics. National Scientific and Technical Research Council (CONICET). La Plata (1900), Buenos Aires, Argentina. Telephone: +54 (0221) 421-1799. Internal: 422 Fax: 425-7980 or 421-1799. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Got what I needed done (thanks Bert!) This is what I went with: metaclass := Metaclass new
superclass: Some class; methodDictionary: MethodDictionary new; setFormat: Some class format;
yourself. theme := metaclass new superclass: Some;
methodDictionary: MethodDictionary new; setFormat: Some format; yourself.
On Sun, Dec 19, 2010 at 10:14 AM, Hernán Morales Durand <[hidden email]> wrote: Hi Casey, -- Casey Ransberger _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |