Table of Contents

Operators

In this tutorial, we will go over all operators available in TableScript.

Concatenation operator

+ is the binary concatenation operator. It concatenates two tables together, appending the elements of the right table at the end of the elements of the left:

tab greeting = "hello" + [" ", "world"];
print(greeting); //prints hello world

You can also use its variation +=, that sets a table to itself concatenated to another:

tab a = ["a", "b"];
a += "c";

print(a); //prints abc

These operators work as expected(performing integer arithmetic) with number tables.

+= is also available for element-wise setting, reducing the table to a single string:

tab a = ["a", "b"];
a.0 += ["h", "2"];

print(a == ["ah2", "b"]); //prints true

Difference operator

- is the binary difference operator. It removes elements of the right table contained in the left table(once per element):

tab a = ["a", "a", "b"];
tab b = a - ["a"];
tab c = a - ["a", "a"];

print(b); //prints ab
print(c); //prints b

You can also use its variation -=, that sets a table to itself removing the elements of another:

tab a = ["a", "a", "b"];
a -= ["a"];

print(a); //prints ab

These operators work as expected(performing integer arithmetic) with number tables.

Product operator

* is the binary product operator. It performs a cartesian product between the elements of two tables:

tab a = ["a", "b"] * ["c", "d"];
print(a); //prints acbcadbd

tab b = ["a", "b"] * 3;
print(b); //prints ababab

tab c = 3 * ["a", "b"];
print(c); //prints aaabbb

You can also use its variation *=, that sets a table to the cartesian product of itself with another:

tab a = ["a", "b"];
a *= 3;

print(a); //prints ababab

These operators work as expected(performing integer arithmetic) with number tables.

Equality operators

== is the binary equality operator. != is the binary inequality operator. They test for equality element by element, and return a boolea table(0 or 1):

print(["a", "b"] != ["ab"] ? "true" : "false"); //prints true
print(["a", "b"] == ["a", "b"] ? "true" : "false"); //prints true
print(["a", "b"] == "ab" ? "true" : "false"); //prints false

Negation operator

! is the unary prefix negation operator. It returns false(0) if a table would be considered true(length > 0) and true(1) if a table would be considered false:

tab t = !["h"]; //["h"] would be considered true because its length is greater than 0
print(t ? "true" : "false"); //prints false

Ternary operator

? and : are the ternary conditional operator. It returns the first expression if the condition is true, and the second if its false:

tab a = ["a", "b", "c"];
tab b = ["a", "b"];
print(a == b ? "true" : "false"); //prints false
print(a == a ? "true" : "false"); //prints true

Comparison operators

>, >=, < and <= are the binary comparison operators. They return a boolean(true(1) or false(0)), returning true if the length of the first table is greater, greater or equal, less or less or equal than the length of the second table:

print(["1"] > ["a", "b"] ? "true" : "false"); //prints false
print(4 > ["a", "b"] ? "true" : "false"); //prints true

Reduction operator

^ is the unary postfix reduction operator. It reduces a table to a single element table joining all its string elements:

tab a = ["a", "b", "c", "def", "g"];
tab b = a^;

print(b == ["abcdefg"] ? "true" : "false"); //prints true

Decomposition operator

% is the unary postfix decomposition operator. It splits all the string elements into chars:

tab a = ["abc", "def", "g"];
tab b = a%;
print(b == ["a", "b", "c", "d", "e", "f", "g"] ? "true" : "false"); //prints true

Containment operator

@ is the binary containment operator. !@ is the binary non-containment operator. The check whether all elements of the left table are contained on the right table, and returns a boolean(true(1) or false(0)):

tab d = ["c", "d", "a", "n", "b"];

print(["a", "b"] @ d ? "true" : "false"); //prints true
print(["a", "b", "m"] @ d ? "true" : "false"); //prints false
print("a" !@ ["b", "c"] ? "true" : "false"); //prints true

It is also used in the syntax of foreach loops:

tab d = ["c", "d", "a", "n", "b"];

foreach l @ d{
	print(l);
}

In the next tutorial, an example program with virtually all features will be explained.