Values

Tao has six kinds of built-in values: Int, Float, Bool, None, String, and List. Everything else is a data instance you define yourself.

Int

Whole numbers. Underscores may separate digits for readability.

42
1_000_000

Float

Numbers with a fractional part.

3.14
0.5

Bool

The two boolean literals, written capitalized.

True
False

None

The absence of a value. Like Ruby’s nil, it is used for “no result” and as the empty half of an error.

String

Double-quoted text. Strings support the escapes \\, \", \n, \r, \t, and \0, and cannot span multiple lines.

"hello"
"hello\nworld"

String interpolation uses a backslash-paren around an identifier:

let name = "world"
"hello \(name)"

Interpolation accepts a simple identifier, not an arbitrary expression. Non-string values are rendered with repr.

Strings are also indexable for reading and writing. An index returns a one-character string, and negative indexes count from the end.

"hello"[0]     // "h"
"hello"[-1]    // "o"
let mut s = "ab"
s[0] = "A"     // "Ab"

List

An ordered collection, written with square brackets.

[1, 2, 3]
[]
["mixed", 1, True, None]

Elements are read and written with an index. Indexes must be integers; negative indexes count from the end, so [-1] is the last element.

[1, 2, 3][0]    // 1
[1, 2, 3][-1]   // 3
let mut xs = [1, 2]
xs[0] = 99      // [99, 2]

Truthiness

Tao follows its own law: only None and False are false. Every other value — including 0, "", and [] — is true.

if 0 { "T" } else { "F" }   // "T"
if "" { "T" } else { "F" }  // "T"
if [] { "T" } else { "F" }  // "T"
if None { "T" } else { "F" }  // "F"

Operators

Arithmetic

+, -, *, /, % require numbers on both sides. Unary - negates a number. Division or modulo by zero is a runtime error.

Dividing two Int values yields an Int; use a Float operand for a fractional result.

1 + 2 * 3    // 7
7 % 3        // 1
7 / 2        // 3
7 / 2.0      // 3.5
-5

"a" + "b" is an error — strings are not concatenated with +.

Comparison

Ordering (> >= < <=) requires numbers. Equality (==, !=) works on any values.

Logical

and / or (also && / ||) short-circuit and return one of their operands, like Ruby:

None or 42     // 42
0 or 5         // 0
1 and 2        // 2
None and 42    // None

! and not negate truthiness.