A variable in FriCAS refers to a value. A variable has a name beginning with an uppercase or lowercase alphabetic character, “%”, or ”!”. Successive characters (if any) can be any of the above, digits, or ”?”. Case is distinguished. The following are all examples of valid, distinct variable names:
a tooBig? a1B2c3%!?
A %j numberOfPoints
beta6 %J numberofpoints
The ”:=” operator is the immediate assignment operator. Use it to associate a value with a variable. The syntax for immediate assignment for a single variable is:
variable := expression
The value returned by an immediate assignment is the value of expression.
a := 1
1
Type: PositiveInteger
The right-hand side of the expression is evaluated, yielding 1. The value is then assigned to a.
b := a
1
Type: PositiveInteger
The right-hand side of the expression is evaluated, yieldig 1. This value is then assigned to b. Thus a and b both have the value 1 after the sequence of assignments.
a := 2
2
Type: PositiveInteger
What is the value of b if a is assigned the value 2?
b
1
Type: PositiveInteger
The value of b is left unchanged.
This is what we mean when we say this kind of assignment is immediate. The variable b has no dependency on a after the initial assignment. This is the usual notion of assignment in programming languages such as C, Pascal, and Fortran.
FriCAS provides delayed assignment with “==”. This implements a delayed evaluation of the right-hand side and dependency checking. The syntax for delayed assignment is
variable == expression
The value returned by a delayed assignment is the unique value of Void.
a == 1
Type: Void
b == a
Type: Void
Using a and b as above, these are the corresponding delayed assignments.
a
Compiling body of rule a to compute value of type PositiveInteger
1
Type: PositiveInteger
The right-hand side of each delayed assignment is left unevaluated until the variables on the left-hand sides are evaluated.
b
Compiling body of rule b to compute value of type PositiveInteger
1
Type: PositiveInteger
This gives the same results as before. But if we change a to 2
a == 2
Compiled code for a has been cleared.
Compiled code for b has been cleared.
1 old definition(s) deleted for function or rule a
Type: Void
Then a evaluates to 2, as expected
a
Compiling body of rule a to compute value of type PositiveInteger
2
Type: PositiveInteger
but the value of b reflects the change to a
b
Compiling body of rule b to compute value of type PositiveInteger
2
Type: PositiveInteger
It is possible to set several variables at the same time by using a tuple of variables and a tuple of expressions. A tuple is a collection of things separated by commas, often surrounded by parentheses. The syntax for multiple immediate assignment is
( var1, var2, ..., varN ) := ( expr1, expr2, ..., exprN )
The value returned by an immediate assignment is the value of exprN.
( x, y ) := ( 1, 2 )
2
Type: PositiveInteger
This sets x to 1 and y to 2. Multiple immediate assignments are parallel in the sense that the expressions on the right are all evaluated before any assignments on the left are made. However, the order of evaluation of these expressions is undefined.
( x, y ) := ( y, x )
1
Type: PositiveInteger
x
2
Type: PositiveInteger
The variable x now has the previous value of y.
y
1
Type: PositiveInteger
The variable y now has the previous value of x.
There is no syntactic form for multiple delayed assignments.