Smalltalk constants

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Smalltalk constants

Delyan Kalchev
Hi,

Is there a good way to create a named constant in Smalltalk. For
example the name MyNamedConstant to be constant bind to the number 2
or even to a non-constant object, like the pseudo-variables nil or
true are bind to their objects and the programmer cannot change them
to point to other objects.

Thanks
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Smalltalk constants

Mark Volkmann
On Nov 5, 2008, at 3:43 AM, Delyan Kalchev wrote:

> Hi,
>
> Is there a good way to create a named constant in Smalltalk. For
> example the name MyNamedConstant to be constant bind to the number 2
> or even to a non-constant object, like the pseudo-variables nil or
> true are bind to their objects and the programmer cannot change them
> to point to other objects.


The recommended way to implement constants in Smalltalk is by writing  
a class method that simply returns the constant value. For example,  
see the class method pi in the Math class. Actually this class also  
represents constants as class variables whose values are set in the  
class initialize method. In this case the class variable Pi is set in  
initialize and that is returned from the class method pi.

---
Mark Volkmann




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Smalltalk constants

Delyan Kalchev
On Wed, Nov 5, 2008 at 2:09 PM, Mark Volkmann <[hidden email]> wrote:

> The recommended way to implement constants in Smalltalk is by writing a
> class method that simply returns the constant value. For example, see the
> class method pi in the Math class. Actually this class also represents
> constants as class variables whose values are set in the class initialize
> method. In this case the class variable Pi is set in initialize and that is
> returned from the class method pi.
>
> ---
> Mark Volkmann
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

Thanks
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners