Operators
From Reia
Contents |
Boolean operators
Reia has 3 boolean operators: and, or, and not. The and and or operators are both binary; the not operator is unary.
The and and or operators both exhibit "short-circuiting" as seen in other languages: if the first term in the comparison is false, the second term is never evaluated. This differs from the traditional Erlang behavior, which is to evaluate both terms regardless of whether the first is false.
The &&, ||, and ! versions of and, or, and not are also available. These are semantically identical to their alphabetic counterparts.
Examples:
>> true and false => false >> true && true => true >> true or false => true >> not true or !true => false
Comparison operators
Reia presents the standard set of comparison operators found in languages with C-like syntax:
- == equal to
- != not equal to
- > greater than
- < less than
- <= less than or equal to
- >= greater than or equal to
Programmers coming from Erlang should beware of the <= operator, which varies from Erlang's =<
Pattern matching comparison
Reia supports a special operator === which performs a pattern matching operation and returns true if the pattern matched or false otherwise. You can think of this operator combining the match behavior of = with the comparison behavior of ===. However, unlike = this operator cannot bind variables and all variables referenced must be bound beforehand.
Arithmetic operators
Reia presents the standard arithmetic operators:
- +: addition
- -: subtraction
- *: multiplication
- /: division
- %: modulus (remainder of a division operation)
In addition, Reia also supports:
- **: exponentation (left hand side to the power of the right hand side)
Bitwise operators
Reia supports the standard set of bitswise operators you may be familiar with from the C family of languages:
- |: bitwise or
- &: bitwise and
- ^: bitwise xor
- ~: bitwise not (unary)
- <<: bitwise left shift
- >>: bitwise right shift
Assignment operators
Any of the aritmetic or bitwise operators can be combined with the "=" operator to perform in place assignments, e.g.:
- +=: add the right hand side to the left hand side
- *=: multiply the left hand side by the right hand side
- <<=: bit shift the left hand side by the right hand side
(etc)
"Splat" operator: *
The "splat" operator * can be used to capture or use a list in place of multiple consecutive arguments. You can think of it as akin to the cons and car operations from Lisp, depending on the context:
>> nums = [3,4,5] => [3,4,5] >> [1,2,*nums] => [1,2,3,4,5]
If you're familiar with Erlang, splat takes the place of the pipe | operator in lists. [a,b,*c] in Reia is equivalent to [A,B|C] in Erlang.
"Bang" operator: !
The unary "bang" operator ! provides the traditional boolean not functionality of the C family of languages.
When appended to the end of method names, ! causes the method receiver to be rebound to the value returned from a method:
>> nums = [1,2,3,4,5] => [1,2,3,4,5] >> nums.reverse!() => [5,4,3,2,1] >> nums => [5,4,3,2,1]
Caret operator (unary): ^
The caret operator ^ supports a special unary form which allows you to use variables as parts of patterns. For more information, see pattern matching.
Conditional operator: ?:
Reia supports the ternary conditional operator you may be familiar with from languages such as C:
>> false ? 'no' : 'yes' => "yes"

