- Variable assignment statement.
- Multiple variable assignment statement.
- Function assignment statement.
- Matrix assignment statement.
- Plot statement
- For statement
- While statement
- If statement
- Keyword statement
- Expression statement
- Expression statement with numbersystem
- Procedure definition statement
- Procedure execution statement
Statements
Several types of statements are supported.Variable assignment statement.
Syntax :
<variable> := <expression>Example :
x:= 5Multiple variable assignment statement.
Syntax :
{ <var1>, ... } := <expression>Example :
{x,y} := {5,7}Function assignment statement.
Syntax :
<function> ( <var1>, ... ) := <expression>Example :
f(x,y) := x+yMatrix assignment statement.
One or more elements in a matrix are assigned a value. If the matrix does not exist, it is created in the environment. If the row and column index selects an element outside the current matrix, the matrix is expanded to include the selected element. Other elements are then assigned the value zero.
Syntax :
<matrix-variable>[row index, column index] := <expression>Example :
M[2,3]:=2*qUse ... as row and/or column index to include all rows/columns.
Example :
M[2,...] := {1,2,3}The row index can be omitted. It is interpreted as follows.
Syntax :
<matrix-variable>[column index] = <matrix-variable>[..., column index]Example :
M[2] := 5Functions, variables including matrices and procedures share name-space. Names are case-sensitive.
The following words are keywords and should not be used as names for variables and matrices:
who, restart, version, div, mod, true, false, and, nand, or, nor, not, xor, if, then, else, while, do, end, for, to, step, next, kill, quit, done, exit, stop, i, pi, e, NaN, inf.
Plot statement
The statement plots one dataset.
Syntax :
plot(<plot type>, <plot symbol>, X, Y)Syntax :
plot(<plot type>, <plot symbol>, Y)Syntax :
plot(<plot type>, <plot symbol>, X, Y, Z)Syntax :
plot(<plot type>, <plot symbol>, X, Y, a, b, c)The plot types
xy, polar, pie, bar, col, par and fun are available. Available plot symbols are dot, star, plus, cross, ring and line. The plot type, the plot symbol and the X vector may be omitted. Then the following default values are used: Plottype xy, plot symbol line and X vector {1,2,...,n}. The plot types bar and col can be used with one or two data series - with two the first data series is the lower values and the second the upper values. Plot type pie works only with one data series. For plot type xy the Y data series is plotted as a function of the X data series. For plot type polar the radia are given in X and the angles in Y. For plot type fun the first argument after an eventual plotsymbol is the function-expression to plot. The next argument indicates the variable and interval for the plot. For plot type par the arguments must contain two function expressions followed by an argument with the independent variable set equal to the selected interval. Every plot statement can take zero, one, two or three additional string arguments. The additional arguments a, b and c are used as 1. axis label, 2.axis label and plot title.Example :
plot(xy,star,{1,2,3,4},{20,3,17,-4})Example :
plot(polar,line,{1,2,3,4},{20,3,17,-4})Example :
plot(bar,{20,3,17,-4})Example :
plot(xy,line,{1,2,3,4},{20,3,17,-4},"Time","Earnings","Results")Example :
plot(fun, k^2-5*k+6,k==[-5..5])Example :
plot(par, cross, sin(t), cos(t), t==[0..2*pi])For statement
The statement list is repeated a number of times.
Syntax :
for <variable> := <expression> to <expression> do <list of statements> nextSyntax :
for <variable> := <expression> to <expression> step <expression> do <list of statements> nextExample :
for a:=1 to 5 step 2 do a^2; a^3 nextWhile statement
The statement repeats a statement list until a condition is true. The condition must be an expression, which can be evaluated to true or false.
Syntax :
while <boolean expression> do <list of statements> endExample :
a:=1: while a<4 do a^2; b:=a: a:=b+1: endIf statement
The if chooses between two statement lists depending upon a condition. The last statement list can be left out. The condition must be an expression, which can be evaluated to true or false.
Syntax :
if <boolean expression> then <list of statements> else <list of statements> endSyntax :
if <boolean expression> then <list of statements> endExample :
if a>5 then b:=3 else c:=2 endKeyword statement
A keyword statement consists of one word only.
who: Lists the environment, i.e. user-defined variables and functions.
restart: Clears the environment.
version: Prints system information.
Expression statement
The result is stored in variable <ans>
Syntax :
<expression>Example :
1+5Expression statement with numbersystem
The result is stored in variable <ans>
Syntax :
<expression> in bin|oct|dec|hex|romanSyntax :
<expression> in base nExample :
1+5 in binProcedure definition statement
The list of statements are stored in the environment under the procedure name. The variables are used to initialize the environment when the procedure is executed.
Syntax :
proc <procedure name>(<variable list>) := (local | global) <statement list> endExample :
proc g(a,b) := local a; b; a*b endProcedure execution statement
The list of statements stored under the procedure name are executed. The values of the expressions are assigned to the variables listed as the procedure was defined. These values can be known to only the function (local) or be remembered when the procedure has executed (global). This must be set when the procedure is defined.
Syntax :
do <procedure name>(<expression list>)Example :
do g(1,2)Use semicolon or colon to separate multiple statements. Colon suppresses printing output, while semicolon allows for output to be printed. The last or only statement does not need a semicolon or a colon. When one is missing, a semicolon is assumed.
Example :
1+2; 2+3: 3+4goto top