Vikari Language Documentation


Available since:  v0.4.0.

Assignment Operators

Vikari supports the following binary assignment operators:

Operator NameSymbolFunction
Left Assignment<<Assign the right operand to the left operand.
Right Assignment>>Assign the left operand to the right operand.

Assignment operators are used in variable declaration statements, and assignment expressions.

Examples

The left assignment operator << assigns the right operand to the left operand. The left operand must be a variable. If the variable does not yet exist, a new variable can be declared and assigned at the same time using this operator.

~:Declare and assign a new variable.:~
foo << 2.7

~:Declare and assign a new variable (with type label).:~
bar:Double << 5.4

~:Reassign an existing variable.:~
foo << bar

The right assignment operator >> assigns the left operand to the right operand. The right operand must be a variable. If the variable does not yet exist, a syntax error will be thrown.

~:Assign a new value to an existing variable.:~
3.14 >> foo
foo >> bar

~:As baz has not been declared, the following is a syntax error.:~
6.28 >> baz

Assignment operator expressions return the result of the value being assigned. They can therefore be used anywhere an expression of that resulting type is then allowed. Chaining of left assignment operators is allowed without a grouping. However, due to right-associativity of right assignment operators, a grouping is then necessary for chaining them together.

~:First, declare some variables to be used.:~
foo, bar, baz

~:Print the result of an assignment.:~
:[foo << 1]: ~:Prints 1.:~
:[1 >> bar]: ~:Also prints 1.:~

~:Chain a series of assignments.:~
:[foo << bar << baz << 2]:     ~:Prints 2.:~
:[[[3 >> foo] >> bar] >> baz]: ~:Prints 3.:~