general arguments expression iterator statement comments func proc
syntax
/*...*/
//...
syntax
(e)
e^e
-e
e*e e/e e%e
e+e e-e
e==e e!=e ee e>=e
float_epsilon
of being mathematically exact. See
float_epsilon .
Special logical expressions of the form objref1 == objref2 (and obj != obj) are also allowed and return 1 (0) if the object references label the same object. This makes the former comparison idiom using object_id obsolete. Logical expressions of the strdef1 == strdef2 cannot be directly compared because of parser consistency reasons. However obj1.string1 == obj2.string2 will return true if the strings are identical in the sense of strcmp .
e&&e
float_epsilon
of 0 and true otherwise. If the entire expression is true
its value is 1.
e||e
float_epsilon
of 0 and true otherwise. If the entire expression is true
its value is 1.
v=e v+=e v-=e v*=e v/=e
v = (v + e)
,
v = (v - e)
,
v = (v * e)
,
v = (v / e)
, respectively.
syntax
stmt
{stmt}
{stmt stmt ...stmt}
Statements exist between the braces following thei = 0 //initialize i j = 0 //initialize j if(vec.x[i] <= 10 && i < vec.size()){ //In the parentheses is an expression: //if the value of the ith element in vec //is less than or equal to 10, and //if i is an index within vec // //Between the braces is/are statement(s): vec1.x[j] = vec.x[i] i = i+1 //increment i by 1 j = j+1 //increment j by 1 } else{ //Here is also a statement i = i+1 //simply go to the next element of vec }
if
and else
commands.
The parentheses after the if
command contain an expression.
syntax
proc name() stmt
prints the square of 5.proc printsquare() {local x x = $1 print x*x } printsquare(5)
Procedures can also be called within other procedures. The code which produces the interactive examples for the Random class contains procedures for both creating the buttons which allow you to select parameters as well as for creating the histograms which appear on the screen.
syntax
func() {stmt1, stmt2, stmt3...}
creates a functionfunc tan() { return sin($1)/cos($1) } tan(PI/8)
tan()
which takes one argument (floating point
or whole number), and contains one
statement.
syntax
iterator name() stmt
In this caseiterator case() {local i for i = 2, numarg() { //must begin at 2 because the first argument is //in reference to the address $&1 = $i //what is at the address will be changed iterator_statement //This is where the iterator statement will //be executed. } }
will print the values 1, 2, 4, 7, -25x=0 for case (&x, 1,2,4,7,-25) { print x //the iterator statement }
The body of the for name(..) statement
is executed in the same
context as a normal for statement. The name is executed in the same
context as a normal procedure.
syntax
$1, $2, $3
refer to the first, second, and third scalar arguments
respectively.
If "i
" is declared as a local variable, $i
refers
to the scalar argument in the position given by the value of i
.
The value of i
must be in the
range {1...numarg()}.
The normal idiom is
for i=1, numarg() {print $i}
Scalar arguments use call by value so the variable in the calling
statement cannot be changed.
If the calling statement has a '&'
prepended to the variable then it is passed by reference and must
be retrieved with the
syntax $&1, $&2, ..., $&i
. If the variable passed by reference
is a one dimensional array then $&1
refers to the first (0th) element
and index i is denoted $&1[i]
. Warning, NO array bounds checking is
done and the array is treated as being one-dimensional. A scalar or
array reference may be passed to another procedure with
&$&1
. To save a scalar reference use the Pointer class.
Retrieval of strdef arguments uses the syntax: $s1, $s2, ..., $si
.
Retrieval of objref arguments uses the syntax: $o1, $o2, ..., $oi
.
Arguments of type strdef
and objref
use call by reference so the calling
value may be changed.
defines a function which multiplies two arguments. Thereforefunc mult(){ return $1*$2 }
mult(4,5)
will return the value 20.
defines a procedure which first prints the string defined in position 3, then prints the product of the two numbers in positions 1 and 2, and finally prints the pointer reference to an object in position 4.proc pr(){ print $s3 print $1*$2 print $o4 }
For a string 's
' which is defined as s = "hello"
, and an
objref 'r
', pr(3,5,s,r)
will return
assuminghello 15 Graph[0]
r
refers to the first graph.