Hi,
I am generating some classes and methods programmatically and got some questions: First: I define(*) classes A and B in two different namespaces, say NA and NB. Then I change class NB.B to have NA.A as superclass (using #superclass:). When I query the subclasses of NA.A via #subclasses I get an empty collection. The RB doesn't show them either in the hierarchy view if NA.A is selected. Is this behavior desired and how can I query subclasses from all namespaces? Second: I define an instance variable a in class A (using #addInstVarName:) and afterwards accessors via #compile:classified. If I browse these methods, the RB surprisingly insists on variable a being undefined, although the generated code works like a charm. Do you have an idea what's causing this? Perhaps these methods I am using during generation are not meant for this purpose? If so, which should I use instead? Thanks in advance, Steffen (*) using #defineClass:superclass:indextedType:private:instanceVariableNames:classInstanceVariableNames:imports:category: _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
> -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On Behalf Of Steffen Märcker > Sent: Monday, January 18, 2010 9:38 AM > To: vwnc > Subject: [vwnc] class and method generation oddities > > Hi, > > I am generating some classes and methods programmatically and got some > questions: > > First: > I define(*) classes A and B in two different namespaces, say NA and NB. > Then I change class NB.B to have NA.A as superclass (using #superclass:). > When I query the subclasses of NA.A via #subclasses I get an empty > collection. The RB doesn't show them either in the hierarchy view if NA.A > is selected. Is this behavior desired and how can I query subclasses from > all namespaces? You have a bug. I think you should use #assignSuperclass: instead of #superclass:. Browse the messages and senders that manipulate the superclass and subclasses variables. You can use the RB and code reader as guides to learn how to programmatically build and manipulate classes and their composition. > Second: > I define an instance variable a in class A (using #addInstVarName:) and > afterwards accessors via #compile:classified. If I browse these methods, > the RB surprisingly insists on variable a being undefined, although the > generated code works like a charm. Do you have an idea what's causing this? > > Perhaps these methods I am using during generation are not meant for this > purpose? If so, which should I use instead? > > Thanks in advance, > Steffen > > > > > (*) using > #defineClass:superclass:indextedType:private:instanceVariableNames:classInstanceVariableNames:imports: > category: > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc Terry =========================================================== Terry Raymond Crafted Smalltalk 80 Lazywood Ln. Tiverton, RI 02878 (401) 624-4517 [hidden email] <http://www.craftedsmalltalk.com> =========================================================== _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
note that #superclass: can be used in certain scenarios.
See "Superpower Adventures in Lightweight Classing" http://www.cincomsmalltalk.com/userblogs/travis/blogView?showComments=true&printTitle=Superpower_Adventures_in_Lightweight_Classing&entry=3440856756 -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Terry Raymond Gesendet: Montag, 18. Januar 2010 16:15 An: [hidden email]; 'vwnc' Betreff: Re: [vwnc] class and method generation oddities > -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On Behalf Of Steffen Märcker > Sent: Monday, January 18, 2010 9:38 AM > To: vwnc > Subject: [vwnc] class and method generation oddities > > Hi, > > I am generating some classes and methods programmatically and got some > questions: > > First: > I define(*) classes A and B in two different namespaces, say NA and NB. > Then I change class NB.B to have NA.A as superclass (using #superclass:). > When I query the subclasses of NA.A via #subclasses I get an empty > collection. The RB doesn't show them either in the hierarchy view if NA.A > is selected. Is this behavior desired and how can I query subclasses from > all namespaces? You have a bug. I think you should use #assignSuperclass: instead of #superclass:. Browse the messages and senders that manipulate the superclass and subclasses variables. You can use the RB and code reader as guides to learn how to programmatically build and manipulate classes and their composition. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Steffen Märcker
Dear Steffen,
you want to move up from using #superclass: to using #assignSuperclass: at the very least. Safer still is to reassign the superclass by redefining it via e.g. | classToRedefine | classToRedefine := NB.B. classToRedefine environment defineClass: classToRedefine name superclass: #{NA.A} indexedType: classToRedefine behaviorType private: ((classToRedefine environment bindingFor: classToRedefine name) ifNil: [false] ifNotNil: [:value | value isPrivate]) instanceVariableNames: classToRedefine instanceVariablesString classInstanceVariableNames: classToRedefine class instanceVariablesString imports: classToRedefine sharedPoolsString category: classToRedefine category asString. thus ensuring system modification recognition. Yours faithfully Niall Ross >Hi, > >I am generating some classes and methods programmatically and got some >questions: > >First: >I define(*) classes A and B in two different namespaces, say NA and NB. >Then I change class NB.B to have NA.A as superclass (using #superclass:). >When I query the subclasses of NA.A via #subclasses I get an empty >collection. The RB doesn't show them either in the hierarchy view if NA.A >is selected. Is this behavior desired and how can I query subclasses from >all namespaces? > >Second: >I define an instance variable a in class A (using #addInstVarName:) and >afterwards accessors via #compile:classified. If I browse these methods, >the RB surprisingly insists on variable a being undefined, although the >generated code works like a charm. Do you have an idea what's causing this? > >Perhaps these methods I am using during generation are not meant for this >purpose? If so, which should I use instead? > >Thanks in advance, >Steffen > > > > >(*) using >#defineClass:superclass:indextedType:private:instanceVariableNames:classInstanceVariableNames:imports:category: >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Terry Raymond
Thank you for pointing out the wrong method.
However, one strange bug remains: Why does #compile:classified: not respect already defined instance variables in my case? I am doing something like: aClass := aNamespace defineClass:supe ... aClass addInstVarName: #myVar. "an inspector confirms the existence of myVar" aClass compile: 'myVar ^myVar' classified: 'accessing'. The method is created but refers to an undeclared variable 'myVar' instead of the already defined instance variable. Do you have a clue what my mistake might be? THX, Steffen Am 18.01.2010, 16:14 Uhr, schrieb Terry Raymond <[hidden email]>: > >> -----Original Message----- >> From: [hidden email] [mailto:[hidden email]] On >> Behalf Of Steffen Märcker >> Sent: Monday, January 18, 2010 9:38 AM >> To: vwnc >> Subject: [vwnc] class and method generation oddities >> >> Hi, >> >> I am generating some classes and methods programmatically and got some >> questions: >> >> First: >> I define(*) classes A and B in two different namespaces, say NA and NB. >> Then I change class NB.B to have NA.A as superclass (using >> #superclass:). >> When I query the subclasses of NA.A via #subclasses I get an empty >> collection. The RB doesn't show them either in the hierarchy view if >> NA.A >> is selected. Is this behavior desired and how can I query subclasses >> from >> all namespaces? > > You have a bug. I think you should use #assignSuperclass: instead of > #superclass:. > Browse the messages and senders that manipulate the superclass and > subclasses variables. > > You can use the RB and code reader as guides to learn how to > programmatically build and > manipulate classes and their composition. > >> Second: >> I define an instance variable a in class A (using #addInstVarName:) and >> afterwards accessors via #compile:classified. If I browse these methods, >> the RB surprisingly insists on variable a being undefined, although the >> generated code works like a charm. Do you have an idea what's causing >> this? >> >> Perhaps these methods I am using during generation are not meant for >> this >> purpose? If so, which should I use instead? >> >> Thanks in advance, >> Steffen >> >> >> >> >> (*) using >> #defineClass:superclass:indextedType:private:instanceVariableNames:classInstanceVariableNames:imports: >> category: >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > Terry > =========================================================== > Terry Raymond > Crafted Smalltalk > 80 Lazywood Ln. > Tiverton, RI 02878 > (401) 624-4517 [hidden email] > <http://www.craftedsmalltalk.com> > =========================================================== > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Steffen
I am not sure what happens when you use a symbol for an ivar name instead of a string, but it should be a string. aClass addInstVarName: 'myVar'. Terry =========================================================== Terry Raymond Crafted Smalltalk 80 Lazywood Ln. Tiverton, RI 02878 (401) 624-4517 [hidden email] <http://www.craftedsmalltalk.com> =========================================================== > -----Original Message----- > From: Steffen Märcker [mailto:[hidden email]] > Sent: Monday, January 18, 2010 12:52 PM > To: Terry Raymond; 'vwnc' > Subject: Re: [vwnc] class and method generation oddities > > Thank you for pointing out the wrong method. > > However, one strange bug remains: Why does #compile:classified: not > respect already defined instance variables in my case? I am doing > something like: > > aClass := aNamespace defineClass:supe ... > aClass addInstVarName: #myVar. "an inspector confirms the existence of > myVar" > aClass > compile: > 'myVar > ^myVar' > classified: > 'accessing'. > > The method is created but refers to an undeclared variable 'myVar' instead > of the already defined instance variable. > Do you have a clue what my mistake might be? > > THX, > Steffen > > > Am 18.01.2010, 16:14 Uhr, schrieb Terry Raymond > <[hidden email]>: > > > > >> -----Original Message----- > >> From: [hidden email] [mailto:[hidden email]] On > >> Behalf Of Steffen Märcker > >> Sent: Monday, January 18, 2010 9:38 AM > >> To: vwnc > >> Subject: [vwnc] class and method generation oddities > >> > >> Hi, > >> > >> I am generating some classes and methods programmatically and got some > >> questions: > >> > >> First: > >> I define(*) classes A and B in two different namespaces, say NA and NB. > >> Then I change class NB.B to have NA.A as superclass (using > >> #superclass:). > >> When I query the subclasses of NA.A via #subclasses I get an empty > >> collection. The RB doesn't show them either in the hierarchy view if > >> NA.A > >> is selected. Is this behavior desired and how can I query subclasses > >> from > >> all namespaces? > > > > You have a bug. I think you should use #assignSuperclass: instead of > > #superclass:. > > Browse the messages and senders that manipulate the superclass and > > subclasses variables. > > > > You can use the RB and code reader as guides to learn how to > > programmatically build and > > manipulate classes and their composition. > > > >> Second: > >> I define an instance variable a in class A (using #addInstVarName:) and > >> afterwards accessors via #compile:classified. If I browse these methods, > >> the RB surprisingly insists on variable a being undefined, although the > >> generated code works like a charm. Do you have an idea what's causing > >> this? > >> > >> Perhaps these methods I am using during generation are not meant for > >> this > >> purpose? If so, which should I use instead? > >> > >> Thanks in advance, > >> Steffen > >> > >> > >> > >> > >> (*) using > >> > #defineClass:superclass:indextedType:private:instanceVariableNames:classInstanceVariableNames:imports: > >> category: > >> _______________________________________________ > >> vwnc mailing list > >> [hidden email] > >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > > > > Terry > > =========================================================== > > Terry Raymond > > Crafted Smalltalk > > 80 Lazywood Ln. > > Tiverton, RI 02878 > > (401) 624-4517 [hidden email] > > <http://www.craftedsmalltalk.com> > > =========================================================== > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |