One of the most amazing features of ZxApp IT is that it makes a terrific
environment for performing mathmatical calculations, etc. Within the
WYSIWYG text of a node, you can create and evaluate expressions,
complete with variables. Later, in the Introduction
to Scripting, you will use these same basic concepts to define and
execute your own functions.
The ad-hoc expression evaluator is invoked by pressing [Control Space]
immediately after an equal sign within the WYSIWYG editor of the node.
ZxApp IT can evaluate any algebraic expression For instance, type
'(5+2)*4=' into the editor and press [Control Space]'. The expression
would be evaluated and the output would be inserted after the equal sign
as follows:
(5+2)*4=28
ZxApp IT recognizes the following algebraic operators:
|
Symbol
|
Notes
|
Example
|
|
+
|
Addition
|
4+3=7
|
|
-
|
Subtraction
|
4-3=1
|
|
/
|
Division
|
4/3=1.33333333333333
|
|
*
|
Multiplication
|
4*3=12
|
|
^
|
Power Of
|
4^3=64
|
|
%
|
Remainder (Modulus)
|
4%3=1
|
|
Symbol
|
Notes
|
Example
|
|
>
|
Greater Than
|
5>2=true
|
|
<
|
Less Than
|
5<2=false
|
|
== (two equal signs)
|
Equal To.
|
5==2=false
|
|
>=
|
Greater Than or Equal To
|
5>=2=true
|
|
<=
|
Less Than or Equal To
|
5<=2=false
|
|
!=
|
Not Equal To.
|
5!=2=true
|
Defining variables is as simple as this;
x: 5
In the above example I have defined a variable named x and assigned it a
value of 5. ZxApp IT knows the syntax for a valid expression and
assigns the value of the expression following the colon, up to the first
character that is not considered as acceptable in a valid expression, to
the variable specified before the colon. It understands that it is
acceptable to have spaces preceeding and following algebraic operators,
such as +, -, /, and *, but not between two numbers, or a number and an
identifier (such as 'x'). The rules turn out to be remarkably simple.
Thus, we could assign a value to a variable using an expression such as;
y:3^3
or
z:x+y
ZxApp IT performs "lazy assignment", meaning that it does not determine
the value of a variable until it is requested by the user. This keeps
the editor from being bogged-down by excessive calculations.
The next obvious question is, "Now how do I use a variable once it is
defined?"
Evaluation is triggered by typing an expression, followed by an equal
sign (=), and then pressing [Control-Space]. If the text of this
section was within ZxApp IT, we could type 'x=[Control Space]' and it
would result in 'x=5'. ZxApp IT looks for variable assignments work
backwards from the expression being calculated. So if we redefined x to
be
x:10
and again typed 'x=[Control Space]', it would result in 'x=10'.
We can evaluate entire expressions, such as 'x+5=[Control Space]', which
would of course be 'x+5=15'.
When we evaluate expressions that are dependent on expressions, such as
z*2, it causes ZxApp IT to go back recursively to find the values of x
and y. But it always uses the location of the expression, and not the
location of intermediate assignments, when determining the current
value. For instance, 'z*2=[Control-Space]' would yield 'z*2=74', since
the value of x at this location within the text is 10, and thus z*2 =
(x+y)*2 = (10+27)*2 = 74.
Worksheets are nothing more than simple tables, with labels inserted for
convenience. To create a worksheet, select [Table]->[Create Worksheet]
Below is an example 3 x 3 worksheet (with some numbers inserted to play
with).
| A1: |
4
|
B1: |
9
|
C1: |
16
|
| A2: |
25
|
B2: |
36
|
C2: |
49
|
| A3: |
64
|
B3: |
81
|
C3: |
100
|
Since this is just simply a table, the labels could be changed to
anything you want. For example you might change the name of 'A1' to be
'two_squared'. Worksheets are covered in more detail in the section on spreadsheets.
Appendix C provides a list
of functions available to you. For the following discussion we will use
the 'sum()' function defined in the Math library. This function allows
you to sum values together, such as 'sum(5,6)=[Control-Space]', which
yields 'sum(5,6)=11'. This by itself seems unimpressive since we could
simply type '5+6=[Control-Space]' and get the same result. But it
begins to get more interesting with the introduction of Double Dot
Notation.
Double dot notation is simply shorthand notation for an array of
variables. We can assign arrays of values to variables like so;
total: [4,9,16,25,36,49,64,81,100]
and use the sum function to calculate that sum(total)=384. This
expression could have been written as;
total2: [A1, A2, A3, B1, B2, B3, C1, C2, C3]
which would yield the same sum(total2)=384. At this point we can
rewrite the expression using double dot notation as;
total3: A1..C3
which yields an identical result; sum(total3)=384. We could, of course
skip the middle-variable (total3), and just compute the value as
'sum(A1..C3)=[Control-Space], which yields 'sum(A1..C3)=384.
To get a better insight into what is happening, consider that total3 is
an array, exactly like total2 is an array. Arrays have a property named
'length' that allow us to determine how many values are in the array,
such that 'A1..C3.length=[Control-Space]' yields 'A1..C3.length=9'. If
you prefer, you could write it as '(A1..C3).length'.
We can next retrieve the individual values of an array using an index
reference; 'A1..C3[3]=[Control-Space]' yields 'A1..C3[3]=25'. Again,
using parenthesis can make the equation more legible; '(A1..C3)[3]=25'.
Right now you might be asking, "why is the third element of the array
equal to 25?". The answer is that ITS NOT!! That is the FOURTH element
of the array. Arrays start at index 0... Thus the first value in the
array is (A1..C3)[0]. The second is (A1..C3)[1], and so on.