Operators

From Reia

Jump to: navigation, search

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.

Numeric operators

Reia presents the standard arithmetic operators: +, -, *, /. In addition, ** can be used to perform exponentation and % returns the modulus or remainder of the division of two numbers.

Personal tools