Causerie:

Constants

Page last modified on July 06, 2014, at 07:39 AM

In keeping with its Smalltalk heritage, causerie does not directly support the idea of constants -- named values that cannot be changed at runtime. Most things about a causerie program may be changed while the program is running: methods may be reassigned, variable values may change, and so forth. The only major exception to this rule lies in unnamed program elements: raw numeric values, string literals, and anonymous blocks. These elements cannot be changed simply because they are not named -- that is, they are not assigned to a symbol and so there is no way for the program to refer to them.

By making judicious use of the preprocessor, you can "name" such an element for use in your own code while preventing it from being changed at runtime:

// Define a "constant"
<$define PI=3.14159"/>

// Now this constant can be used in code
float var sqrtPi := PI sqrt;

The compiler never sees the name attached to such a constant because the preprocessor replaces every instance that occurs with the value you have defined. As a result, the constant has no symbol attached to it when the program runs and so the value cannot be accessed to be changed.

causerie

developers

recent changes

edit SideBar


All site content copyright © its various contributors.
Licensed under Creative Commons License