A value is assigned to a variable using the assignment (>>
) operator.
This operator requires a left side which is an expression resulting in a
value and a right side which is the name of a variable. If the variable does
not exist it will be created and its type will be the type of the value
resulting from the expression. If the variable already exists then its
current value will be overwritten with the new one. If the type of the
value resulting from the expression differs from the variable type the value
will be coerced to the type of the variable. Some examples are shown below.
"hello" >> s1 "" >> s2 123 >> s2 s1 + s2 >> s3
The first line creates a string variable s1
and assigns the string
literal "hello"
to it. The second line creates a string variable s2
and assigns an empty string to it. The third line assigns the numeric literal
123
to the string variable s2
thus converting it into a string.
The fourth line concatenates the two string variables contents and assigns the
result to a new string variable s3
which has the value "hello123"
.
Go to the first, previous, next, last section, table of contents.