Docs Demo Source

Operators

YASL supports a wide range of operators. A table listing them all, along with their precendence, can be found here. Below is a more in-depth description of each operator.

Arithmetic Operators

YASL supports the following arithmetic operators:

Float division always returns a float. Integer division and modulo are only defined for int values. All other arithmetic operators return an int if both operands are int, otherwise it returns a float.

Bitwise Operators

YASL supports the following bitwise operators:

All bitwise operators are only defined for int operands, and return an int.

Logical Operators

YASL supports the following logical operators:

All logical operators can be used with any value, treating all falsey values as false and all truthy values as true. Logical and and logical or short circuit, and return either the left or right operand depending on Truthiness.

Comparison Operators

YASL supports the following comparison operators:

The ordering operators (<, >, >=, <=) are defined for strings and numbers.

The equality operator (==) compares by value. It coerces int s to float s if needed. Otherwise, no coercions are done. undef == undef is false.

The strict equality operator compares by identity. For scalar types, it behaves the same as ==, except it compares undef === undef as true rather than false, and will not coerce between numeric types. For list s, table s, str s, etc, it returns true iff the two objects compared are the object in memory.

Length Operator

The length operator len is defined for str (returning the length), list (returning the length) and table (returning the number of elements).

Concatenation Operator

The concatenation operator ~ concatenates its two operands, turning each to a string first if it is not already a string.

Ternary Operator

The ternary operator takes 3 arguments of any type, and returns the second if the first is truthy, otherwise it returns the third.

Undef Coalescing Operator

The undef coalescing operator ?? returns the left operand if it is not undef, otherwise it returns the right operand. This can be useful for setting default values or checking if a value has been defined.