Basic Types
Do is dynamically typed. Values carry their type at runtime, and variables can hold any type.
Int and Float share the abstract Num supertype and its common
rounding, sign, extrema, and clamping methods. The math module
provides transcendental functions and integer number theory.
Integers (Int)
128-bit signed integers.
Integers support arithmetic (+, -, *, /, //, %), bitwise
(&, |, ^, ~, <<, >>), and comparison operators.
/ performs floating point division and results in a float. The // operator
performs Euclidean division and % computes the Euclidean remainder, such that
x == (x // y) * y + (x % y). This means both always yield Ints as
results.
Floats (Float)
64-bit floating point.
// and % likewise perform Euclidean division and remainder operations for
floats, meaning that // always returns an Int while % returns a Float.
Strings (Str)
Immutable UTF-8 strings, written as bare literals at statement level, as quoted strings, or as multi-line here strings:
Binary Strings (Bin)
Immutable byte sequences that may contain arbitrary (non-UTF-8) data, written
with a b"..." prefix:
See Strings for every literal form of both types, along with
escaping and interpolation. Str and Bin also support a wide variety of
methods (Str, Bin).
Booleans (Bool)
true and false.
Nil (nil)
A generic "absent" marker and the result of functions, expressions, and statements with nothing interesting to return.
Symbols (Sym)
Globally canonical identifiers that are more efficient to hash and compare than
Str. Used for literal dictionary keys, key arguments in variadic argument
packs, object fields, ad-hoc enumerated constants, etc.
Symbols can also be created from strings with sym:
Data Structures
See Data Structures for arrays, dictionaries, records, sets, and tuples.
Type Inspection
Every value has an associated type object that represents its type. The
built-in types (Int, Float, Str, Bool, Sym, Array, Dict, etc.)
each have a corresponding type object available in the standard library.
Type is the type of types. Use the lowercase type function to query or
test types:
# Get the type of a value (returns the type object)
assert_eq (type 42) $Int
assert_eq (type "hello") $Str
assert_eq (type [1, 2]) $Array
assert_eq (type nil) $Nil
# Test if a value is an instance of a type
assert (type 42 Int)
assert (type "hello" Str)
assert (type nil Nil)
User-defined classes work the same way:
See Classes for defining your own types.
Type Conversions
The built-in types can be called as functions to convert values: