home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
calculat
/
sm30a.zip
/
SYMBMATH.H12
< prev
next >
Wrap
Text File
|
1993-11-07
|
3KB
|
54 lines
3.3.3 Assignment Statements
The assignement in SymbMath language is similar to assignment in
such language as PASCAL.
An assignment operator is :=
The assignment statement specifies that a new value of expr2
be assigned to expr1, and saved into memory. The form of the assignment
statements is
expr1 := expr2
You can use assignment for storing result.
You can assign the result of calculation or any formula to a
variable with a command like: X := SIN(4.2).
The assignemts are useful for long calculations. You can save
yourself a lot of recalculations by always storing the results of your
calculations in your own variables instead of leaving them in the default
variable last.
You can destroy the assignmemt to X with the command clear(X). If
X stored a large list, you could regain a considerable amount of memory by
clearing X. Also, since a variable and a function can have the same name,
you can clear a variable p, not a function p(x).
The assignment operator is also used in the definition of
a function or procedure.
Variables can be used in function definitions, and that leads to an
important difference between functions and variables. When a variable is
defined, all terms of the definition are evaluated. When a function is
defined, its terms are not evaluated; they are evaluated when the function
is evaluated. That means that if a component of the function definition is
changed, that change will be reflected the next time the function is
evaluated.
e.g.
IN: p:=2+3 # 2+3 is evaluated at the time of assignment,
# p is assigned with 5.
OUT: p := 5
IN: p(x):=2+3 # 2+3 is evaluated when the value of p(x) is requested,
# p(x) is assigned with 2+3.
OUT: p(x) := 2+3
If the left hand side of the assignment is a variable, it is the immediate
assignment (i.e. expr2 is evaluated at the time of assignment); if the
left hand side is a function, it is the delayed assignment (i.e. expr2 is
evaluated when the value of expr1 is requested).
You can force all the components of a function to be evaluated when
the function is defined by preceding the function with the command eval():
f(x_) := eval(2+3) # f(x_) is assigned with 5
Note that not only a variable but also any expression can be
assigned. e.g. x:=2, sin(x)/cos(x) := tan(x), a>0 := 1.
Clear a variable, function or expression from assignment by
clear(x) # clear x from assignment.
clear(f(x)) # clear f(x) from assignment.
clear(a>0) # clear a>0 from assume(a>0).