XMLMath
XMLMath
 
Font size:      

Declaring and Using Variables

Declaring and Using Variables

Declarations are closely related to input parameters: they have a name and a value and can be read further down the expression tree using the family of <link> tags.

From the perspective of the <link> tag, input parameters and declarations are equivalent. This also means that declarations and input parameters should not use the same names to avoid name clashes.

The example below declares a variable x and then computes x + x + x:

							
<expression xmlns="http://xmlmath.org/1.0">
  <add>

    <declare name="x">
      <long value="5"/>
    </declare>

    <linkLong name="x"/>
    <linkLong name="x"/>
    <linkLong name="x"/>
  </add>
</expression>
						

The main difference between input parameters and declarations is that the first can only be used in the expression's root tag, while declarations can be defined at each level of the expression tree.

In contrast to most variables in programming languages, declared values in xmlmath cannot be assigned a value other than the value represented by the declaration's child element. Xmlmath does not have an assignment operator.