Hi all,
For programming my Lego Mindstorms NXT I have to use codes like 16r1F. But I actually want to be able to use "readable" codes. In a language like Java I will do that with a static const, but as far as I know I have to do it with symbols in Smalltalk. How do I create a symbol so that it is accible by all the classes? Thanks in advance, Mispunt. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Feb 27, 2007, at 10:08 , Mispunt wrote:
> Hi all, > > For programming my Lego Mindstorms NXT I have to use codes like 16r1F. > But I actually want to be able to use "readable" codes. In a language > like Java I will do that with a static const, but as far as I know I > have to do it with symbols in Smalltalk. No, there is a better way. If you are inside one class (or its subclasses), you would use "class variables", one per constant. You add them in the class template: Object subclass: #Bla instanceVariableNames: '' classVariableNames: 'Const1 Const2' poolDictionaries: '' category: 'Bert-Bla' and the initialization code is in a class-side #initialize method: initialize "self initialize" Const1 := 16r1F. Const2 := 12345. You need to execute the "self initialize" in the browser to do the initialization. It will be executed automatically when loaded into another image. Class variables are capitalized because they are sort-of "global", they can be used in the defining class, its metaclass, and all their subclasses. If you need to give access to these variables across the class hierarchies, then you would do the same, but as a subclass of SharedPool: SharedPool subclass: #BlaConstants instanceVariableNames: '' classVariableNames: 'Const1 Const2' poolDictionaries: '' category: 'Bert-Bla'. To use this "pool" of variables in another class, list it as a "pool dictionary": Object subclass: #Bla instanceVariableNames: '' classVariableNames: '' poolDictionaries: 'BlaConstants' category: 'Bert-Bla' This makes all class variables of BlaConstants available to Bla as if they were class variables. There are quite a few other ways to allow "global" variables in Smalltalk, but this one is the "clean" way to do it which works nicely with tools like Monticello. - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Thanks Bert, it works. When I am using the poolDictionary it isn't
possible to use the constants in the Workspace right? or do I have to write methods for them when I want to use them? (well I don't want to, because it is just for testing purpose). Mispunt. On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > > Hi all, > > > > For programming my Lego Mindstorms NXT I have to use codes like 16r1F. > > But I actually want to be able to use "readable" codes. In a language > > like Java I will do that with a static const, but as far as I know I > > have to do it with symbols in Smalltalk. > > No, there is a better way. > > If you are inside one class (or its subclasses), you would use "class > variables", one per constant. You add them in the class template: > > Object subclass: #Bla > instanceVariableNames: '' > classVariableNames: 'Const1 Const2' > poolDictionaries: '' > category: 'Bert-Bla' > > and the initialization code is in a class-side #initialize method: > > initialize > "self initialize" > Const1 := 16r1F. > Const2 := 12345. > > You need to execute the "self initialize" in the browser to do the > initialization. It will be executed automatically when loaded into > another image. > > Class variables are capitalized because they are sort-of "global", > they can be used in the defining class, its metaclass, and all their > subclasses. If you need to give access to these variables across the > class hierarchies, then you would do the same, but as a subclass of > SharedPool: > > SharedPool subclass: #BlaConstants > instanceVariableNames: '' > classVariableNames: 'Const1 Const2' > poolDictionaries: '' > category: 'Bert-Bla'. > > To use this "pool" of variables in another class, list it as a "pool > dictionary": > > Object subclass: #Bla > instanceVariableNames: '' > classVariableNames: '' > poolDictionaries: 'BlaConstants' > category: 'Bert-Bla' > > This makes all class variables of BlaConstants available to Bla as if > they were class variables. > > There are quite a few other ways to allow "global" variables in > Smalltalk, but this one is the "clean" way to do it which works > nicely with tools like Monticello. > > - Bert - > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
You could simply use a browser as workspace. Like, the class comment
area. Or to access the variables directly from anywhere: (BlaConstants classPool at: #Const1) Or you can add them to the workspace itself. A workspace provides variable bindings, but only for temporary (lowercase) variables (*). To add your class variable bindings, get the halo on a workspace, select "inspect model" from the grey debug handle menu. You get an inspector for the workspace. In the lower text pane, execute this: bindings := Dictionary new. BlaConstants classPool keysAndValuesDo: [:k :v | bindings at: 'c',k put: v] Then you can use "cConst1" in the workspace :) - Bert - (*) this could be changed in Parser>>correctVariable:interval: to allow upper-case variables, too. The workspace is the "requestor". On Feb 27, 2007, at 11:04 , Mispunt wrote: > Thanks Bert, it works. When I am using the poolDictionary it isn't > possible to use the constants in the Workspace right? or do I have to > write methods for them when I want to use them? (well I don't want to, > because it is just for testing purpose). > > Mispunt. > > On 2/27/07, Bert Freudenberg <[hidden email]> wrote: >> On Feb 27, 2007, at 10:08 , Mispunt wrote: >> >> > Hi all, >> > >> > For programming my Lego Mindstorms NXT I have to use codes like >> 16r1F. >> > But I actually want to be able to use "readable" codes. In a >> language >> > like Java I will do that with a static const, but as far as I >> know I >> > have to do it with symbols in Smalltalk. >> >> No, there is a better way. >> >> If you are inside one class (or its subclasses), you would use "class >> variables", one per constant. You add them in the class template: >> >> Object subclass: #Bla >> instanceVariableNames: '' >> classVariableNames: 'Const1 Const2' >> poolDictionaries: '' >> category: 'Bert-Bla' >> >> and the initialization code is in a class-side #initialize method: >> >> initialize >> "self initialize" >> Const1 := 16r1F. >> Const2 := 12345. >> >> You need to execute the "self initialize" in the browser to do the >> initialization. It will be executed automatically when loaded into >> another image. >> >> Class variables are capitalized because they are sort-of "global", >> they can be used in the defining class, its metaclass, and all their >> subclasses. If you need to give access to these variables across the >> class hierarchies, then you would do the same, but as a subclass of >> SharedPool: >> >> SharedPool subclass: #BlaConstants >> instanceVariableNames: '' >> classVariableNames: 'Const1 Const2' >> poolDictionaries: '' >> category: 'Bert-Bla'. >> >> To use this "pool" of variables in another class, list it as a "pool >> dictionary": >> >> Object subclass: #Bla >> instanceVariableNames: '' >> classVariableNames: '' >> poolDictionaries: 'BlaConstants' >> category: 'Bert-Bla' >> >> This makes all class variables of BlaConstants available to Bla as if >> they were class variables. >> >> There are quite a few other ways to allow "global" variables in >> Smalltalk, but this one is the "clean" way to do it which works >> nicely with tools like Monticello. >> >> - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hello Bert,
BF> Or you can add them to the workspace itself. A workspace provides BF> variable bindings, but only for temporary (lowercase) variables (*). BF> To add your class variable bindings, get the halo on a workspace, BF> select "inspect model" from the grey debug handle menu. You get an BF> inspector for the workspace. In the lower text pane, execute this: BF> bindings := Dictionary new. BF> BlaConstants classPool keysAndValuesDo: [:k :v | bindings at: 'c',k BF> put: v] BF> Then you can use "cConst1" in the workspace :) enlightening lesson, as always. Do you by any chance plan to hold a course on Squeak? Cheers, Herbert mailto:[hidden email] _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Feb 27, 2007, at 12:39 , Herbert König wrote:
> Hello Bert, > > BF> Or you can add them to the workspace itself. A workspace provides > BF> variable bindings, but only for temporary (lowercase) variables > (*). > BF> To add your class variable bindings, get the halo on a workspace, > BF> select "inspect model" from the grey debug handle menu. You get an > BF> inspector for the workspace. In the lower text pane, execute this: > > BF> bindings := Dictionary new. > BF> BlaConstants classPool keysAndValuesDo: [:k :v | bindings at: > 'c',k > BF> put: v] > > BF> Then you can use "cConst1" in the workspace :) > > enlightening lesson, as always. > > Do you by any chance plan to hold a course on Squeak? Not really, not enough time. Planning a course takes time, even more than actually holding it. Now, an informal hacking weekend not too far away, preferably with attractions for my family nearby, bringing experienced and new Squeakers together, that would be something I might want to attend ... - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Mispunt
After some better testing, It doesn't work :S It seems that the
initialize of the constants class isn't running... (the normal classVariableNames are working...) I have to use the poolDictionary because there are some codes that return in a lot of classes.. Mispunt On 2/27/07, Mispunt <[hidden email]> wrote: > Thanks Bert, it works. When I am using the poolDictionary it isn't > possible to use the constants in the Workspace right? or do I have to > write methods for them when I want to use them? (well I don't want to, > because it is just for testing purpose). > > Mispunt. > > On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > > > > Hi all, > > > > > > For programming my Lego Mindstorms NXT I have to use codes like 16r1F. > > > But I actually want to be able to use "readable" codes. In a language > > > like Java I will do that with a static const, but as far as I know I > > > have to do it with symbols in Smalltalk. > > > > No, there is a better way. > > > > If you are inside one class (or its subclasses), you would use "class > > variables", one per constant. You add them in the class template: > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla' > > > > and the initialization code is in a class-side #initialize method: > > > > initialize > > "self initialize" > > Const1 := 16r1F. > > Const2 := 12345. > > > > You need to execute the "self initialize" in the browser to do the > > initialization. It will be executed automatically when loaded into > > another image. > > > > Class variables are capitalized because they are sort-of "global", > > they can be used in the defining class, its metaclass, and all their > > subclasses. If you need to give access to these variables across the > > class hierarchies, then you would do the same, but as a subclass of > > SharedPool: > > > > SharedPool subclass: #BlaConstants > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla'. > > > > To use this "pool" of variables in another class, list it as a "pool > > dictionary": > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: '' > > poolDictionaries: 'BlaConstants' > > category: 'Bert-Bla' > > > > This makes all class variables of BlaConstants available to Bla as if > > they were class variables. > > > > There are quite a few other ways to allow "global" variables in > > Smalltalk, but this one is the "clean" way to do it which works > > nicely with tools like Monticello. > > > > - Bert - > > > > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
What do you mean with "isn't running"? As I wrote, you have to
execute it manually whenever you change the initialize method. - Bert - On Feb 27, 2007, at 13:33 , Mispunt wrote: > After some better testing, It doesn't work :S It seems that the > initialize of the constants class isn't running... (the normal > classVariableNames are working...) I have to use the poolDictionary > because there are some codes that return in a lot of classes.. > > Mispunt > > On 2/27/07, Mispunt <[hidden email]> wrote: >> Thanks Bert, it works. When I am using the poolDictionary it isn't >> possible to use the constants in the Workspace right? or do I have to >> write methods for them when I want to use them? (well I don't want >> to, >> because it is just for testing purpose). >> >> Mispunt. >> >> On 2/27/07, Bert Freudenberg <[hidden email]> wrote: >> > On Feb 27, 2007, at 10:08 , Mispunt wrote: >> > >> > > Hi all, >> > > >> > > For programming my Lego Mindstorms NXT I have to use codes >> like 16r1F. >> > > But I actually want to be able to use "readable" codes. In a >> language >> > > like Java I will do that with a static const, but as far as I >> know I >> > > have to do it with symbols in Smalltalk. >> > >> > No, there is a better way. >> > >> > If you are inside one class (or its subclasses), you would use >> "class >> > variables", one per constant. You add them in the class template: >> > >> > Object subclass: #Bla >> > instanceVariableNames: '' >> > classVariableNames: 'Const1 Const2' >> > poolDictionaries: '' >> > category: 'Bert-Bla' >> > >> > and the initialization code is in a class-side #initialize method: >> > >> > initialize >> > "self initialize" >> > Const1 := 16r1F. >> > Const2 := 12345. >> > >> > You need to execute the "self initialize" in the browser to do the >> > initialization. It will be executed automatically when loaded into >> > another image. >> > >> > Class variables are capitalized because they are sort-of "global", >> > they can be used in the defining class, its metaclass, and all >> their >> > subclasses. If you need to give access to these variables across >> the >> > class hierarchies, then you would do the same, but as a subclass of >> > SharedPool: >> > >> > SharedPool subclass: #BlaConstants >> > instanceVariableNames: '' >> > classVariableNames: 'Const1 Const2' >> > poolDictionaries: '' >> > category: 'Bert-Bla'. >> > >> > To use this "pool" of variables in another class, list it as a >> "pool >> > dictionary": >> > >> > Object subclass: #Bla >> > instanceVariableNames: '' >> > classVariableNames: '' >> > poolDictionaries: 'BlaConstants' >> > category: 'Bert-Bla' >> > >> > This makes all class variables of BlaConstants available to Bla >> as if >> > they were class variables. >> > >> > There are quite a few other ways to allow "global" variables in >> > Smalltalk, but this one is the "clean" way to do it which works >> > nicely with tools like Monticello. >> > >> > - Bert - >> > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
I am sorry, I did mean execute. I hoped that it would execute
initialize when the class (or variableNames) where called by the program.. After running/execute the initialize method it is working :) Thanks for you'r help, Mispunt On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > What do you mean with "isn't running"? As I wrote, you have to > execute it manually whenever you change the initialize method. > > - Bert - > > On Feb 27, 2007, at 13:33 , Mispunt wrote: > > > After some better testing, It doesn't work :S It seems that the > > initialize of the constants class isn't running... (the normal > > classVariableNames are working...) I have to use the poolDictionary > > because there are some codes that return in a lot of classes.. > > > > Mispunt > > > > On 2/27/07, Mispunt <[hidden email]> wrote: > >> Thanks Bert, it works. When I am using the poolDictionary it isn't > >> possible to use the constants in the Workspace right? or do I have to > >> write methods for them when I want to use them? (well I don't want > >> to, > >> because it is just for testing purpose). > >> > >> Mispunt. > >> > >> On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > >> > On Feb 27, 2007, at 10:08 , Mispunt wrote: > >> > > >> > > Hi all, > >> > > > >> > > For programming my Lego Mindstorms NXT I have to use codes > >> like 16r1F. > >> > > But I actually want to be able to use "readable" codes. In a > >> language > >> > > like Java I will do that with a static const, but as far as I > >> know I > >> > > have to do it with symbols in Smalltalk. > >> > > >> > No, there is a better way. > >> > > >> > If you are inside one class (or its subclasses), you would use > >> "class > >> > variables", one per constant. You add them in the class template: > >> > > >> > Object subclass: #Bla > >> > instanceVariableNames: '' > >> > classVariableNames: 'Const1 Const2' > >> > poolDictionaries: '' > >> > category: 'Bert-Bla' > >> > > >> > and the initialization code is in a class-side #initialize method: > >> > > >> > initialize > >> > "self initialize" > >> > Const1 := 16r1F. > >> > Const2 := 12345. > >> > > >> > You need to execute the "self initialize" in the browser to do the > >> > initialization. It will be executed automatically when loaded into > >> > another image. > >> > > >> > Class variables are capitalized because they are sort-of "global", > >> > they can be used in the defining class, its metaclass, and all > >> their > >> > subclasses. If you need to give access to these variables across > >> the > >> > class hierarchies, then you would do the same, but as a subclass of > >> > SharedPool: > >> > > >> > SharedPool subclass: #BlaConstants > >> > instanceVariableNames: '' > >> > classVariableNames: 'Const1 Const2' > >> > poolDictionaries: '' > >> > category: 'Bert-Bla'. > >> > > >> > To use this "pool" of variables in another class, list it as a > >> "pool > >> > dictionary": > >> > > >> > Object subclass: #Bla > >> > instanceVariableNames: '' > >> > classVariableNames: '' > >> > poolDictionaries: 'BlaConstants' > >> > category: 'Bert-Bla' > >> > > >> > This makes all class variables of BlaConstants available to Bla > >> as if > >> > they were class variables. > >> > > >> > There are quite a few other ways to allow "global" variables in > >> > Smalltalk, but this one is the "clean" way to do it which works > >> > nicely with tools like Monticello. > >> > > >> > - Bert - > >> > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
I suspect you are "thinking in Java". Indeed, when you run a Java
program, its class variables will be initialized when the class is loaded into the virtual machine, in other words the first time you reference the class. But Squeak is different; it's a live image system. When you are editing the class, you're actually making changes to the class in the running system. When you restart Squeak, the entire memory image of the virtual machine is reloaded from the last saved image, including the state of any class variables (and instance variables, and processes, etc). Cheers, Greg. On Tue, 2007-02-27 at 07:51, Mispunt wrote: > I am sorry, I did mean execute. I hoped that it would execute > initialize when the class (or variableNames) where called by the > program.. > After running/execute the initialize method it is working :) > > Thanks for you'r help, > > Mispunt > > On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > > What do you mean with "isn't running"? As I wrote, you have to > > execute it manually whenever you change the initialize method. > > > > - Bert - > > > > On Feb 27, 2007, at 13:33 , Mispunt wrote: > > > > > After some better testing, It doesn't work :S It seems that the > > > initialize of the constants class isn't running... (the normal > > > classVariableNames are working...) I have to use the poolDictionary > > > because there are some codes that return in a lot of classes.. > > > > > > Mispunt > > > > > > On 2/27/07, Mispunt <[hidden email]> wrote: > > >> Thanks Bert, it works. When I am using the poolDictionary it isn't > > >> possible to use the constants in the Workspace right? or do I have to > > >> write methods for them when I want to use them? (well I don't want > > >> to, > > >> because it is just for testing purpose). > > >> > > >> Mispunt. > > >> > > >> On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > > >> > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > >> > > > >> > > Hi all, > > >> > > > > >> > > For programming my Lego Mindstorms NXT I have to use codes > > >> like 16r1F. > > >> > > But I actually want to be able to use "readable" codes. In a > > >> language > > >> > > like Java I will do that with a static const, but as far as I > > >> know I > > >> > > have to do it with symbols in Smalltalk. > > >> > > > >> > No, there is a better way. > > >> > > > >> > If you are inside one class (or its subclasses), you would use > > >> "class > > >> > variables", one per constant. You add them in the class template: > > >> > > > >> > Object subclass: #Bla > > >> > instanceVariableNames: '' > > >> > classVariableNames: 'Const1 Const2' > > >> > poolDictionaries: '' > > >> > category: 'Bert-Bla' > > >> > > > >> > and the initialization code is in a class-side #initialize method: > > >> > > > >> > initialize > > >> > "self initialize" > > >> > Const1 := 16r1F. > > >> > Const2 := 12345. > > >> > > > >> > You need to execute the "self initialize" in the browser to do the > > >> > initialization. It will be executed automatically when loaded into > > >> > another image. > > >> > > > >> > Class variables are capitalized because they are sort-of "global", > > >> > they can be used in the defining class, its metaclass, and all > > >> their > > >> > subclasses. If you need to give access to these variables across > > >> the > > >> > class hierarchies, then you would do the same, but as a subclass of > > >> > SharedPool: > > >> > > > >> > SharedPool subclass: #BlaConstants > > >> > instanceVariableNames: '' > > >> > classVariableNames: 'Const1 Const2' > > >> > poolDictionaries: '' > > >> > category: 'Bert-Bla'. > > >> > > > >> > To use this "pool" of variables in another class, list it as a > > >> "pool > > >> > dictionary": > > >> > > > >> > Object subclass: #Bla > > >> > instanceVariableNames: '' > > >> > classVariableNames: '' > > >> > poolDictionaries: 'BlaConstants' > > >> > category: 'Bert-Bla' > > >> > > > >> > This makes all class variables of BlaConstants available to Bla > > >> as if > > >> > they were class variables. > > >> > > > >> > There are quite a few other ways to allow "global" variables in > > >> > Smalltalk, but this one is the "clean" way to do it which works > > >> > nicely with tools like Monticello. > > >> > > > >> > - Bert - > > >> > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Greg is right, so you need to either load the class into a new image that
doesn't have it, since loading a class executes the class side #initialize method, or you need to execute the method yourself and save the image. Ron > From: Greg Trasuk > Sent: Tuesday, February 27, 2007 10:30 AM > > I suspect you are "thinking in Java". Indeed, when you run a Java > program, its class variables will be initialized when the class is > loaded into the virtual machine, in other words the first time you > reference the class. > > But Squeak is different; it's a live image system. When you are editing > the class, you're actually making changes to the class in the running > system. When you restart Squeak, the entire memory image of the virtual > machine is reloaded from the last saved image, including the state of > any class variables (and instance variables, and processes, etc). > > Cheers, > > Greg. > > On Tue, 2007-02-27 at 07:51, Mispunt wrote: > > I am sorry, I did mean execute. I hoped that it would execute > > initialize when the class (or variableNames) where called by the > > program.. > > After running/execute the initialize method it is working :) > > > > Thanks for you'r help, > > > > Mispunt > > > > On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > > > What do you mean with "isn't running"? As I wrote, you have to > > > execute it manually whenever you change the initialize method. > > > > > > - Bert - > > > > > > On Feb 27, 2007, at 13:33 , Mispunt wrote: > > > > > > > After some better testing, It doesn't work :S It seems that the > > > > initialize of the constants class isn't running... (the normal > > > > classVariableNames are working...) I have to use the poolDictionary > > > > because there are some codes that return in a lot of classes.. > > > > > > > > Mispunt > > > > > > > > On 2/27/07, Mispunt <[hidden email]> wrote: > > > >> Thanks Bert, it works. When I am using the poolDictionary it isn't > > > >> possible to use the constants in the Workspace right? or do I have > to > > > >> write methods for them when I want to use them? (well I don't want > > > >> to, > > > >> because it is just for testing purpose). > > > >> > > > >> Mispunt. > > > >> > > > >> On 2/27/07, Bert Freudenberg <[hidden email]> wrote: > > > >> > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > > >> > > > > >> > > Hi all, > > > >> > > > > > >> > > For programming my Lego Mindstorms NXT I have to use codes > > > >> like 16r1F. > > > >> > > But I actually want to be able to use "readable" codes. In a > > > >> language > > > >> > > like Java I will do that with a static const, but as far as I > > > >> know I > > > >> > > have to do it with symbols in Smalltalk. > > > >> > > > > >> > No, there is a better way. > > > >> > > > > >> > If you are inside one class (or its subclasses), you would use > > > >> "class > > > >> > variables", one per constant. You add them in the class template: > > > >> > > > > >> > Object subclass: #Bla > > > >> > instanceVariableNames: '' > > > >> > classVariableNames: 'Const1 Const2' > > > >> > poolDictionaries: '' > > > >> > category: 'Bert-Bla' > > > >> > > > > >> > and the initialization code is in a class-side #initialize > method: > > > >> > > > > >> > initialize > > > >> > "self initialize" > > > >> > Const1 := 16r1F. > > > >> > Const2 := 12345. > > > >> > > > > >> > You need to execute the "self initialize" in the browser to do > the > > > >> > initialization. It will be executed automatically when loaded > into > > > >> > another image. > > > >> > > > > >> > Class variables are capitalized because they are sort-of > "global", > > > >> > they can be used in the defining class, its metaclass, and all > > > >> their > > > >> > subclasses. If you need to give access to these variables across > > > >> the > > > >> > class hierarchies, then you would do the same, but as a subclass > of > > > >> > SharedPool: > > > >> > > > > >> > SharedPool subclass: #BlaConstants > > > >> > instanceVariableNames: '' > > > >> > classVariableNames: 'Const1 Const2' > > > >> > poolDictionaries: '' > > > >> > category: 'Bert-Bla'. > > > >> > > > > >> > To use this "pool" of variables in another class, list it as a > > > >> "pool > > > >> > dictionary": > > > >> > > > > >> > Object subclass: #Bla > > > >> > instanceVariableNames: '' > > > >> > classVariableNames: '' > > > >> > poolDictionaries: 'BlaConstants' > > > >> > category: 'Bert-Bla' > > > >> > > > > >> > This makes all class variables of BlaConstants available to Bla > > > >> as if > > > >> > they were class variables. > > > >> > > > > >> > There are quite a few other ways to allow "global" variables in > > > >> > Smalltalk, but this one is the "clean" way to do it which works > > > >> > nicely with tools like Monticello. > > > >> > > > > >> > - Bert - > > > >> > > > > > > > _______________________________________________ > > > Beginners mailing list > > > [hidden email] > > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
Another alternative is to create a class with a bunch of methods that
represent the constants. The methods are simple: codeThatMeansSomething ^'16r1F' The neat thing is that it is dynamic and all the rules of late binding and message lookup come into play, you can build object structures with proxies, decorators, composites, and so on. I actually did this on a large system (for money). It started out as a bunch of tables and we ended up with 3 instances that had rather insane interfaces (thousands of methods*). We thought it would be really slow, but it turned out to be measurably faster than dictionary lookups. Even better, we had revision history for our "dictionaries" because it was all methods. * Oh, wait, I forgot I was in Squeak. Thousands of methods is no big deal. Bert Freudenberg wrote: > On Feb 27, 2007, at 10:08 , Mispunt wrote: > >> Hi all, >> >> For programming my Lego Mindstorms NXT I have to use codes like 16r1F. >> But I actually want to be able to use "readable" codes. In a language >> like Java I will do that with a static const, but as far as I know I >> have to do it with symbols in Smalltalk. > > > No, there is a better way. > > If you are inside one class (or its subclasses), you would use "class > variables", one per constant. You add them in the class template: > > Object subclass: #Bla > instanceVariableNames: '' > classVariableNames: 'Const1 Const2' > poolDictionaries: '' > category: 'Bert-Bla' > > and the initialization code is in a class-side #initialize method: > > initialize > "self initialize" > Const1 := 16r1F. > Const2 := 12345. > > You need to execute the "self initialize" in the browser to do the > initialization. It will be executed automatically when loaded into > another image. > > Class variables are capitalized because they are sort-of "global", > they can be used in the defining class, its metaclass, and all their > subclasses. If you need to give access to these variables across the > class hierarchies, then you would do the same, but as a subclass of > SharedPool: > > SharedPool subclass: #BlaConstants > instanceVariableNames: '' > classVariableNames: 'Const1 Const2' > poolDictionaries: '' > category: 'Bert-Bla'. > > To use this "pool" of variables in another class, list it as a "pool > dictionary": > > Object subclass: #Bla > instanceVariableNames: '' > classVariableNames: '' > poolDictionaries: 'BlaConstants' > category: 'Bert-Bla' > > This makes all class variables of BlaConstants available to Bla as if > they were class variables. > > There are quite a few other ways to allow "global" variables in > Smalltalk, but this one is the "clean" way to do it which works > nicely with tools like Monticello. > > - Bert - > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Well, I don't have thousands of methods :) but when the application is
running to slow, I will remember this option :) On 3/2/07, David Mitchell <[hidden email]> wrote: > Another alternative is to create a class with a bunch of methods that > represent the constants. The methods are simple: > > codeThatMeansSomething > ^'16r1F' > > The neat thing is that it is dynamic and all the rules of late binding > and message lookup come into play, you can build object structures with > proxies, decorators, composites, and so on. > > I actually did this on a large system (for money). It started out as a > bunch of tables and we ended up with 3 instances that had rather insane > interfaces (thousands of methods*). We thought it would be really slow, > but it turned out to be measurably faster than dictionary lookups. Even > better, we had revision history for our "dictionaries" because it was > all methods. > > * Oh, wait, I forgot I was in Squeak. Thousands of methods is no big deal. > > > Bert Freudenberg wrote: > > > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > > >> Hi all, > >> > >> For programming my Lego Mindstorms NXT I have to use codes like 16r1F. > >> But I actually want to be able to use "readable" codes. In a language > >> like Java I will do that with a static const, but as far as I know I > >> have to do it with symbols in Smalltalk. > > > > > > No, there is a better way. > > > > If you are inside one class (or its subclasses), you would use "class > > variables", one per constant. You add them in the class template: > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla' > > > > and the initialization code is in a class-side #initialize method: > > > > initialize > > "self initialize" > > Const1 := 16r1F. > > Const2 := 12345. > > > > You need to execute the "self initialize" in the browser to do the > > initialization. It will be executed automatically when loaded into > > another image. > > > > Class variables are capitalized because they are sort-of "global", > > they can be used in the defining class, its metaclass, and all their > > subclasses. If you need to give access to these variables across the > > class hierarchies, then you would do the same, but as a subclass of > > SharedPool: > > > > SharedPool subclass: #BlaConstants > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla'. > > > > To use this "pool" of variables in another class, list it as a "pool > > dictionary": > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: '' > > poolDictionaries: 'BlaConstants' > > category: 'Bert-Bla' > > > > This makes all class variables of BlaConstants available to Bla as if > > they were class variables. > > > > There are quite a few other ways to allow "global" variables in > > Smalltalk, but this one is the "clean" way to do it which works > > nicely with tools like Monticello. > > > > - Bert - > > > > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by David Mitchell-10
codeThatMeansSomething
^'16r1F' copy Is better! Ron > From: David Mitchell > > Another alternative is to create a class with a bunch of methods that > represent the constants. The methods are simple: > > codeThatMeansSomething > ^'16r1F' > > The neat thing is that it is dynamic and all the rules of late binding > and message lookup come into play, you can build object structures with > proxies, decorators, composites, and so on. > > I actually did this on a large system (for money). It started out as a > bunch of tables and we ended up with 3 instances that had rather insane > interfaces (thousands of methods*). We thought it would be really slow, > but it turned out to be measurably faster than dictionary lookups. Even > better, we had revision history for our "dictionaries" because it was > all methods. > > * Oh, wait, I forgot I was in Squeak. Thousands of methods is no big deal. > > > Bert Freudenberg wrote: > > > On Feb 27, 2007, at 10:08 , Mispunt wrote: > > > >> Hi all, > >> > >> For programming my Lego Mindstorms NXT I have to use codes like 16r1F. > >> But I actually want to be able to use "readable" codes. In a language > >> like Java I will do that with a static const, but as far as I know I > >> have to do it with symbols in Smalltalk. > > > > > > No, there is a better way. > > > > If you are inside one class (or its subclasses), you would use "class > > variables", one per constant. You add them in the class template: > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla' > > > > and the initialization code is in a class-side #initialize method: > > > > initialize > > "self initialize" > > Const1 := 16r1F. > > Const2 := 12345. > > > > You need to execute the "self initialize" in the browser to do the > > initialization. It will be executed automatically when loaded into > > another image. > > > > Class variables are capitalized because they are sort-of "global", > > they can be used in the defining class, its metaclass, and all their > > subclasses. If you need to give access to these variables across the > > class hierarchies, then you would do the same, but as a subclass of > > SharedPool: > > > > SharedPool subclass: #BlaConstants > > instanceVariableNames: '' > > classVariableNames: 'Const1 Const2' > > poolDictionaries: '' > > category: 'Bert-Bla'. > > > > To use this "pool" of variables in another class, list it as a "pool > > dictionary": > > > > Object subclass: #Bla > > instanceVariableNames: '' > > classVariableNames: '' > > poolDictionaries: 'BlaConstants' > > category: 'Bert-Bla' > > > > This makes all class variables of BlaConstants available to Bla as if > > they were class variables. > > > > There are quite a few other ways to allow "global" variables in > > Smalltalk, but this one is the "clean" way to do it which works > > nicely with tools like Monticello. > > > > - Bert - > > > > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Did I miss a smiley?
Returning a string makes no sense at all given the OP. And that new meme of senselessly adding #copy to every literal string is a bad one. Stop it. - Bert - On Mar 2, 2007, at 15:23 , Ron Teitelbaum wrote: > codeThatMeansSomething > ^'16r1F' copy > > Is better! > > Ron > >> From: David Mitchell >> >> Another alternative is to create a class with a bunch of methods that >> represent the constants. The methods are simple: >> >> codeThatMeansSomething >> ^'16r1F' >> >> The neat thing is that it is dynamic and all the rules of late >> binding >> and message lookup come into play, you can build object structures >> with >> proxies, decorators, composites, and so on. >> >> I actually did this on a large system (for money). It started out >> as a >> bunch of tables and we ended up with 3 instances that had rather >> insane >> interfaces (thousands of methods*). We thought it would be really >> slow, >> but it turned out to be measurably faster than dictionary lookups. >> Even >> better, we had revision history for our "dictionaries" because it was >> all methods. >> >> * Oh, wait, I forgot I was in Squeak. Thousands of methods is no >> big deal. >> >> >> Bert Freudenberg wrote: >> >>> On Feb 27, 2007, at 10:08 , Mispunt wrote: >>> >>>> Hi all, >>>> >>>> For programming my Lego Mindstorms NXT I have to use codes like >>>> 16r1F. >>>> But I actually want to be able to use "readable" codes. In a >>>> language >>>> like Java I will do that with a static const, but as far as I >>>> know I >>>> have to do it with symbols in Smalltalk. >>> >>> >>> No, there is a better way. >>> >>> If you are inside one class (or its subclasses), you would use >>> "class >>> variables", one per constant. You add them in the class template: >>> >>> Object subclass: #Bla >>> instanceVariableNames: '' >>> classVariableNames: 'Const1 Const2' >>> poolDictionaries: '' >>> category: 'Bert-Bla' >>> >>> and the initialization code is in a class-side #initialize method: >>> >>> initialize >>> "self initialize" >>> Const1 := 16r1F. >>> Const2 := 12345. >>> >>> You need to execute the "self initialize" in the browser to do the >>> initialization. It will be executed automatically when loaded into >>> another image. >>> >>> Class variables are capitalized because they are sort-of "global", >>> they can be used in the defining class, its metaclass, and all their >>> subclasses. If you need to give access to these variables across the >>> class hierarchies, then you would do the same, but as a subclass of >>> SharedPool: >>> >>> SharedPool subclass: #BlaConstants >>> instanceVariableNames: '' >>> classVariableNames: 'Const1 Const2' >>> poolDictionaries: '' >>> category: 'Bert-Bla'. >>> >>> To use this "pool" of variables in another class, list it as a "pool >>> dictionary": >>> >>> Object subclass: #Bla >>> instanceVariableNames: '' >>> classVariableNames: '' >>> poolDictionaries: 'BlaConstants' >>> category: 'Bert-Bla' >>> >>> This makes all class variables of BlaConstants available to Bla >>> as if >>> they were class variables. >>> >>> There are quite a few other ways to allow "global" variables in >>> Smalltalk, but this one is the "clean" way to do it which works >>> nicely with tools like Monticello. >>> >>> - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Well, I missed the fact that the codes weren't strings, so that part is
my bad. My point was simply that I've found it useful to have an object whose methods are acting as the keys in a dictionary. This works regardless of what objects were the values. Bert Freudenberg wrote: > Did I miss a smiley? > > Returning a string makes no sense at all given the OP. > > And that new meme of senselessly adding #copy to every literal string > is a bad one. Stop it. > > - Bert - > > On Mar 2, 2007, at 15:23 , Ron Teitelbaum wrote: > >> codeThatMeansSomething >> ^'16r1F' copy >> >> Is better! >> >> Ron >> >>> From: David Mitchell >>> >>> Another alternative is to create a class with a bunch of methods that >>> represent the constants. The methods are simple: >>> >>> codeThatMeansSomething >>> ^'16r1F' >>> >>> The neat thing is that it is dynamic and all the rules of late binding >>> and message lookup come into play, you can build object structures >>> with >>> proxies, decorators, composites, and so on. >>> >>> I actually did this on a large system (for money). It started out as a >>> bunch of tables and we ended up with 3 instances that had rather >>> insane >>> interfaces (thousands of methods*). We thought it would be really >>> slow, >>> but it turned out to be measurably faster than dictionary lookups. >>> Even >>> better, we had revision history for our "dictionaries" because it was >>> all methods. >>> >>> * Oh, wait, I forgot I was in Squeak. Thousands of methods is no >>> big deal. >>> >>> >>> Bert Freudenberg wrote: >>> >>>> On Feb 27, 2007, at 10:08 , Mispunt wrote: >>>> >>>>> Hi all, >>>>> >>>>> For programming my Lego Mindstorms NXT I have to use codes like >>>>> 16r1F. >>>>> But I actually want to be able to use "readable" codes. In a >>>>> language >>>>> like Java I will do that with a static const, but as far as I know I >>>>> have to do it with symbols in Smalltalk. >>>> >>>> >>>> >>>> No, there is a better way. >>>> >>>> If you are inside one class (or its subclasses), you would use "class >>>> variables", one per constant. You add them in the class template: >>>> >>>> Object subclass: #Bla >>>> instanceVariableNames: '' >>>> classVariableNames: 'Const1 Const2' >>>> poolDictionaries: '' >>>> category: 'Bert-Bla' >>>> >>>> and the initialization code is in a class-side #initialize method: >>>> >>>> initialize >>>> "self initialize" >>>> Const1 := 16r1F. >>>> Const2 := 12345. >>>> >>>> You need to execute the "self initialize" in the browser to do the >>>> initialization. It will be executed automatically when loaded into >>>> another image. >>>> >>>> Class variables are capitalized because they are sort-of "global", >>>> they can be used in the defining class, its metaclass, and all their >>>> subclasses. If you need to give access to these variables across the >>>> class hierarchies, then you would do the same, but as a subclass of >>>> SharedPool: >>>> >>>> SharedPool subclass: #BlaConstants >>>> instanceVariableNames: '' >>>> classVariableNames: 'Const1 Const2' >>>> poolDictionaries: '' >>>> category: 'Bert-Bla'. >>>> >>>> To use this "pool" of variables in another class, list it as a "pool >>>> dictionary": >>>> >>>> Object subclass: #Bla >>>> instanceVariableNames: '' >>>> classVariableNames: '' >>>> poolDictionaries: 'BlaConstants' >>>> category: 'Bert-Bla' >>>> >>>> This makes all class variables of BlaConstants available to Bla as if >>>> they were class variables. >>>> >>>> There are quite a few other ways to allow "global" variables in >>>> Smalltalk, but this one is the "clean" way to do it which works >>>> nicely with tools like Monticello. >>>> >>>> - Bert - >>> > > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |