Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

Data Types

Aussom has nine built-in data types: null, bool, int, double, string, list, map, callback, and object. You do not declare the type of a variable - whatever you assign decides the type.

null

null is the absence of a value. It is its own type, and it evaluates to false in conditional expressions.

x = null;
if (x == null) {
    c.log("nothing here");
}

A common use of null is "we have not loaded this yet" or "the caller did not supply this argument."

bool

A boolean. Two literals: true and false.

ok = true;
if (ok) { c.log("yes"); }
if (false) { c.log("never runs"); }

In a conditional, integers, doubles, and strings also have a truthy sense - any non-zero number is true, and any non-empty string is true. The Operators page covers truthiness in detail.

int

A 64-bit signed integer (the same range as a Java long). Literals are runs of decimal digits. Negative numbers use a unary minus.

n1 = 1;
n2 = -23456;
n3 = 2345566823434;
n4 = 0;

There is no separate byte, short, or long - just int.

double

A double-precision floating point number, the same as a Java double.

A double literal must have at least one digit on each side of the decimal point. Bare forms like .5 or 1. are not valid.

d1 = 1.0;
d2 = -57392.238432532;
d3 = 0.0;

string

A sequence of characters. Strings can be written with single or double quotes, and they can also span multiple lines using triple double-quotes.

a = "Hello World!";
b = 'It''s a fine day.';
c = 'Use a "double quote" inside a single-quoted string.';
d = "Use a 'single quote' inside a double-quoted string.";
e = "Escape \"the\" same kind with a backslash.";

The supported escape sequences are:

Sequence Character
\t Tab
\n Newline
\r Carriage return
\" Double quote (in "..." strings)
\' Single quote (in '...' strings)
\\ Backslash

A triple-quoted string spans multiple lines without \n and supports the same escapes, plus \"\"\" to embed a literal """.

greeting = """Hello,
this string spans
multiple lines.""";

list

An ordered, dynamically-sized collection of values. List items can be of any mix of types.

items = [];                  // empty list
items @= "Hi";               // append a string
items @= 10;                 // append an int
items @= true;               // append a bool

count = #items;              // number of items, here 3
first = items[0];            // index access, here "Hi"

The append operator is @=. The count operator is #. List indexes are zero-based and integer. Out-of-range access raises an exception, unless wrapped in the safe-access ? operator (see Operators).

map

An unordered collection of key-value pairs. Keys are strings; values can be any type.

person = {};
person["name"] = "Avery";
person["age"] = 30;

c.log(person["name"]);       // "Avery"
n = #person;                 // number of keys, here 2

Maps can be defined with literal syntax. Keys may be unquoted when they are valid identifiers, or wrapped in quotes for keys with spaces or special characters.

config = {
    host: "localhost",
    port: 8080,
    "feature flag": true
};

To iterate a map, the loop variable is the key:

for (key : config) {
    c.log(key + " = " + config[key]);
}

callback

A reference to a function, created with the :: operator followed by a function name. Callbacks let you pass a function as a value - useful for event handlers, list sorting, and async APIs.

class App {
    public main(args) {
        cb = ::onClick;
        this.register(cb);
    }

    public register(cb) {
        // pretend this stored cb for later
    }

    public onClick() {
        c.log("clicked");
    }
}

You can also pass the callback inline at the call site: this.register(::onClick). Calling a callback is done by the API that holds it, not directly by name.

object

Any instance of a class is an object. The new operator allocates an instance and runs the constructor.

class Greeter {
    public name = "";

    public Greeter(string Name) {
        this.name = Name;
    }

    public greet() {
        return "Hello " + this.name;
    }
}

class App {
    public main(args) {
        g = new Greeter("Avery");
        c.log(g.greet());
        c.log(g.name);
    }
}

Output:

Hello Avery
Avery

object is the most flexible type because every class becomes an object type when instantiated. When you write object as a function argument's type annotation, any instance of any class is accepted.

What to read next

  • Operators - arithmetic, string concatenation, list and map operators, and the safe-access ?.
  • Functions - type-annotated arguments, default values, and variadic functions.