Scalar messages are parsed from left to right without precedence rules. The expr class should be used if controlling the order of evaluation is needed.
Many operations change the number stored in the object. For example, all the arithmetic operators (+, -, *, /, ^) do the operation and store the result in the object's value instance variable. There are two forms of each of the function methods, for example, sqrt! and sqrt?. Message names that end in ! change the object's value. Message names that end in ? do not change the object's value.
Any numeric argument can be a floating point number or a string. If a string is given, it must parse as a floating point number using C floating point syntax.
Note: When creating instances of the scalar class, particularly in scripts, it is safest to enclose the names in quotes. Scalar is one of the classes that returns a value when an instance name is referenced, not the name.
upper is the upper value to perform upper truncation if upper_truncate is set to true (non-zero value).
lower is the lower value to perform lower truncation if lower_truncate is set to true (non-zero value).
upper_truncate is a flag to perform upper truncation if set to true (non-zero value).
lower_truncate is a flag to perform lower truncation if set to true (non-zero value).
mod is a mod value to perform arithmetic module mod. Default is zero.
+ value ... Adds each value in turn to scalar value. Upper and lower truncation are performed after each operation.
* argument Multiply scalar value by the argument. Upper and lower truncation are performed after each operation.
/ argument Divide scalar value by the argument. Upper and lower truncation are performed after each operation.
^ argument Calculate scalar value to the power of argument. Upper and lower truncation are performed after each operation.
= argument Set scalar value (synonym to value=).
value= argument Set scalar value to the argument.
value? Return scalar value.
? Return scalar value (synonym to value?).
pointer? Return pointer to the value.
mod= argument Set the mod value to perform arithmetic modulo argument.
mod? Return the mod value.
upper= argument Set upper value to perform upper truncation if upper_truncates is set to true (non-zero value).
upper? Return upper value.
lower= argument Set lower value to perform lower truncation if lower_truncates set to true (non-zero value).
lower? Return lower value.
upperon! Set upper_truncate to true.
upperoff! Set upper_truncate to false (zero value).
loweron! Set lower_truncate to true.
loweroff! Set lower_truncate to false (zero value).
upper_truncate= argument Set upper_truncate value.
upper_truncate? Return upper_truncate value.
lower_truncate= argument Set lower_truncate value.
lower_truncate? Return lower_truncate value.
atan2: (x,y) Calculate arc tangent of x/y. The scalar object's value is updated.
tan! Calculate tangent of scalar value. The scalar object's value is updated.
tan? Calculate and return tangent of scalar value. The scalar object's value is not changed.
sin! Calculate sin of scalar value. The scalar object's value is updated.
sin? Calculate and return sin of scalar value. The scalar object's value is not changed.
cos! Calculate cosine of scalar value. The scalar object's value is updated.
cos? Calculate and return cosine of scalar value. The scalar object's value is not changed.
abs! Calculate absolute value of scalar value. The scalar object's value is updated.
abs? Calculate and return absolute value of scalar value. The scalar object's value is not changed.
log! Calculate natural logarithm of scalar value. The scalar object's value is updated.
log? Calculate and return natural logarithm of scalar value. The scalar object's value is not changed.
sqrt! Calculate square root of scalar value. The scalar object's value is updated.
sqrt? Calculate and return square root of scalar value. The scalar object's value is not changed.
rand! Calculate a random integer (using function rand() provided by C language run-time support). The scalar object's value is updated.
rand? Calculate and return random integer (using function rand() provided by C language run-time support). The scalar object's value is not changed.
drand48! Calculate a random floating point number between 0.0 and 1.0 using the drand48() function. The scalar object's value is updated.
drand48? Calculate and return a random floating point number between 0.0 and 1.0 using the drand48() function. The scalar object's value is not changed.
max: (x,y,z,...) Calculate maximum of the list of numbers. The scalar object's value is updated.
min: (x,y,z,...) Calculate minimum of the list of numbers. The scalar object's value is updated.
reciprocal! Calculate the reciprocal of the current value. The scalar object's value is updated.
reciprocal? Calculate the reciprocal of the current value and return it on the argument stack. The scalar object's value is not changed.
pop! Moves the previously pushed value on top of the stack and makes it the current scalar value. No value is returned.
pop? Returns the current scalar value and then does a pop!. This is equivalent to a ? followed by a pop!.
push! Push the scalar value on the stack so that it can be retrieved later with pop! or pop?.
stack? Returns the scalar object's current stack, from top to bottom, on the argument stack.
parser trace_on!;
scalar new: `sc1' = 5; scalar new: `sc2' = 7; scalar new: `sc3' = sc1 + sc2; -- now sc3 is equal to 12
collection new: all_scalars
members= [scalar instances?] ;
all_scalars print: value;
sc2 push!; sc3 = sc1 + [sc2 * 2 ?]; sc2 pop!; -- now sc3 is equal to 19 and sc2 is still 7
all_scalars print: value;
sc3 = sc1 + [sc2 * 3 ?]; -- now sc3 is equal to 26 and sc2 is equal to 21
all_scalars print: value;
sc3 = sc1 * [sc2 push! + 3 pop?]; -- set sc3 = sc1 * (sc2 + 3)
all_scalars print: value;
parser trace_off!;