next up previous contents index
Next: Defining functions Up: Constants and functions Previous: Introduction

Defining constants

 
tex2html_wrap_inline33790 tex2html_wrap_inline33790 Syntax

  1. BD>c : %C=E tex2html_wrap_inline33712

  2. BD>c : %C= tex2html_wrap_inline33712

    BD-E tex2html_wrap_inline33712

where C is the name of the constant, and E is any valid equation.

tex2html_wrap_inline33806 tex2html_wrap_inline33806

Constants have names, generally alphanumeric strings which begin with a letter, and are referenced by prefixing the name with a % symbol. Index notation is only allowed to the extent of numerical indices, and not indices representing unknowns (use functions instead). Hence, the name tex2html_wrap_inline36118 is allowed (meaning constant tex2html_wrap_inline36120 with known index 2), but the name tex2html_wrap_inline36122 is disallowed.

The first form of the syntax has the definition part following immediately after the name part. As an alternative, for interactive prompting of constant inputs, the second form of the syntax prompts for the definition part from the keyboard.

The definition part, E, is any valid equation. Thus, for example, E might consist of a simple real number, or some more complicated formula. Whichever, the result of the equation will be a single number and the constant will take this value until explicitly deleted or overwritten.

Constants can be deleted by using the XC:  command, and they may also be redefined. It is an error if an unrecognised constant is found in an equation.

For an example, suppose that y is a data-carrier with observations tex2html_wrap_inline36124 . The code shown in Figure 7.1 defines the constant %sum, initialising it to zero, and then accumulates the sum of the tex2html_wrap_inline36126 's in the %sum constant. This sum is then output. Notice that the initialisation is strictly necessary.

  figure7806
Figure 7.1:  Using constants

 



David Wooff
Wed Oct 21 15:14:31 BST 1998