Can a constant be global?

Robert Brenstein rjb at robelko.com
Mon Mar 27 07:37:14 EST 2006


>>Replicating constant behavior at global level has been discussed 
>>quite a lot in the past, and not only on this list, but... it is a 
>>lot more complicated than it seems at first glance. So, for now at 
>>least, there is no way to make a global behave like a constant 
>>through declaration. It is up to you to designate some globals as 
>>global constants, like using a different prefix than for global 
>>variables.
>
>But the problem there is where do you actually set them? Obviously 
>you have to make sure they are set before another stack/card/control 
>uses them.
>
>That's why I decided that a Constant Library was a better way to go.
>
>All the Best
>Dave

Well, yes, that is exactly one of the problems. Another, for example, 
what happens if you make a mistake in assigning a value and need to 
change it?

So, yes, your Constant Library using functions is one of the 
reasonable solutions. Making your own classes of globals is another. 
One can also have a global array to hold your constants, like 
myConstants["pi"]. Initializing these in your own project is best 
done in openstack or preopenstack of the mainstack. However, in your 
big reusable system, that would not work, so for you the Constant 
Library is probably an optimal solution.

Robert



More information about the Use-livecode mailing list