assign
This function assigns a value to one or multiple variable which are specified in the 2nd and further parameters containing a code piece or
string containing the assignment destination.
Ad-hoc operations (like ++, --, etc. next to the destination variable) are not allowed here.
You can use assign as a function call to branch off an intermeditate calculation into a separate variable. The variable is immediately available
while calculating the expression is still in progress, i.e. you can use the assigned variable further to the right in side the expression. See example further below.
Indirect parameter passing is disabled
2
No. | Type | Description |
---|---|---|
2 input |
all types | Value to assign The specified value provided in this parameter will be assigned in the target variable. |
2, .. code |
variable :string |
destination variables Make sure to add a ':' in front of the string expression if you want to execute string. Ad-hoc operations are not allowed here. |
Type | Description |
---|---|
all types | Value in 1st parameter is passed through the return value. Useful when branching off an intermediate calculation in the expression into one or more destination variables. |
v[] = "b[]";
echo("Calling 'assign' as a procedure call:");
assign( 456, c[] );
assign( 123, :v[] ); // Write to variable b[]
assign( 789, :"d[]");
// Note the required colon. Otherwise v[] is the variable to assign to.
echo("Variable b[] = ", b[] );
echo("Variable c[] = ", c[] );
echo("Variable d[] = ", d[], new line );
echo("Calling 'assign' as a function call:");
c[] = assign( sqrt(81), b[] ) *2;
echo;
echo("Branch off value: ", b[]);
echo("Full calculation: ", c[], new line );
d[] = assign( sqrt(81), x[] ) * (x[]-1);
echo("Use assigned variable in same expression: ", x[] );
echo("Result is: ", d[], new line );
echo(new line, "Assigning to multiple variables in a single statement:");
v[] = 'c[]'; // :v[] means writeing to c[]
assign( 100, b[], :v[], :'d[]', e[thousand] );
echo( b[], ' ', c[], ' ', d[], ' ', e[thousand] );
Calling 'assign' as a procedure call:
Variable b[] = 123
Variable c[] = 456
Variable d[] = 789
Calling 'assign' as a function call:
Branch off value: 9
Full calculation: 18
Use assigned variable in same expression: 9
Result is: 72
Assigning to multiple variables in a single statement:
100 100 100 100