|
Re: Where to 'declare' symbols: msg#00120lang.smalltalk.squeak.beginners
On Mon, Aug 13, 2007 at 09:53:12PM -0400, John Almberg wrote: > Sorry... probably 'symbol' isn't the right word, since as far as I > know, something like #aSymbol doesn't have any value other than it's > own identity. > > What I really want is a named constant that has a value. Like > iAmAConstant = 5. Is there such a thing in Smalltalk? > Two ways; both are common. "First, and simplest, implement a message that returns the constant:" MyClass >> mySpecialNumber ^ 5 "Second, use a class pool variable:" Object subclass: #MyClass instanceVariableNames: '' classVariableNames: 'MySpecialConstant' poolDictionaries: '' category: 'MyCategory' "Set its value in the CLASS-SIDE initialize method:" MyClass class >> initialize MySpecialConstant := 5 "Don't forget to call MyClass initialize. Monticello will automatically do this ONCE" MyClass initialize -- Matthew Fulmer -- http://mtfulmer.wordpress.com/ Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: adding methods to a class at runtime, Mark Volkmann |
|---|---|
| Next by Date: | Re: adding methods to a class at runtime, David Mitchell |
| Previous by Thread: | Re: Where to 'declare' symbols, John Almberg |
| Next by Thread: | Re: Where to 'declare' symbols, John Almberg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |