NeturalMath Language Definition and Syntax

Limitations on Variables

Limitations on Variable Names

While NeturalMath allows variables to be named pretty much anything, there are a few limitations. Variable names must start with a letter (either upper or lower case). They cannot be named the same thing as any existing variable, function, or keyword. They may also not be named the same as any of the words on the Reserved Names list. If a variable is improperly named, NeturalMath will return an error. By convention, private variables and functions are typically named using lower Camel or mixed case (lower first character, and upper for each subsequent word). Public and Global variables are typically named using upper Camel or Pascal case (first letter is capitalized). This also maintains compatibility with .NET naming conventions. NeturalMath is case sensitive, so two variables with the same name, but different cases are seen as two distinct variables. This is important to be aware of when reusing variable names. A variable name must be unique with its scope.
// each of these is a unique variable
myVAR = 10
MyVar = 11
myvar = 12 
MYVAR = 13

Limitations on Variable Assignments

Variables may be assigned a value either via an expression, or by using the @= operator to "fix" the value (See Expressions for more information). There are no limits to what fixed values my be assigned to a variable, within the constraints of NeturalMath. For "fixed" values, the only limitations are those of the assigned data type (See Data Types for more information). There are limitations on variables that are assigned an expression value. Variables cannot be assigned an expression that contains the same variable reference. Variables may also not be assigned an expression which would otherwise create a circular reference back to the same variable. If this is attempted, NeturalMath will return an error. The code below shows a few examples of invalid variable assignments.
// All of these examples will create an error in NeturalMath

// variable defined in terms of itself
x = x + 3  

// circular reference
y = z + 10
z = y * 12


Programmers used to working in other languages may have a hard time with this concept at first, as it is common to assign a variable a value based on its previous value. These individuals should keep in mind that the value being assigned to the variable is not a discrete value, but rather an expression based on some other value. Assigning a variable to an expression containing itself would not only create a circular reference inside the system causing it to enter an infinite loop, but it would also be mathematically invalid. Consider the example above. If x is defined as x} {{+ 3, then algebraically, we could simplify this statement down by subtracting the variable x from both sides of the equation. This would yield the ridiculous result 0 = 3! Obviously, such a violation of the laws of mathematics cannot be allowed. Programmers wishing to reuse their variables without creating a circular reference should consider using the @= operator instead to "fix" the value of an expression, as shown below (See Expressions for more information).
x = 10
x @= x+ 3  // avoids self-reference because the value of the expression is computed before being assigned to x

See Also

Constants
Constraining Variables
Data Types
Declaring Variables
Expressions
Reserved Names
Variables and Scope

Last edited Oct 16, 2010 at 5:34 PM by zanethorn, version 5

Comments

No comments yet.