NeturalMath Language Definition and Syntax

User Defined Constants

Users may define their own constant values in NeturalMath by using the const keyword. This forces the following variable assignment into a constant value. Once the constant variable has been set, it may never be changed. Please see documentation on individual data types for more information on how to use a literal constant.

User Defined Constants are not supported via use of the const keyword in the current version of NeturalMath. Constants are currenly only supported via the .NET class libraries. Full support for the const keyword is planned for v 0.3.6. Please see Roadmap for more information.

Defining a variable as a constant

Constants will always retain the value that they were originally set to by the system. Constants are defined the same way as any other variable, but prefixed with the const keyword:
:> const x = 10
:> const y = 'teddy'
:> print x

:> print y

:> // Next line throws an exception
:> x = 2

Constants do not always have to be defined in terms of a constant. They may also be defined as the result of an expression:
:> const x = sin(10)
:> const y = 'two' + 'two'
:> print x

:> print y


Using a constant in an expression

Constants may be used in expressions the same way as any other variable would be.
:> const x = 10
:> y = x + 2
:> print y


See Also:


Last edited Oct 14, 2010 at 3:39 PM by zanethorn, version 1


No comments yet.