Types

Dust is a dynamically typed language. Its primitive types available are the following:

Booleans

A boolean can either be true or false. They support the usual boolean operations:

// logical and
x && y

// logical or
x || y

// logical not
!x

The && and || operators perform short-circuit evaluation. For example, false && f() evaluates to false without evaluating f().

Numbers

⚠️ Dust doesn't parse floating point literals yet

There is not distinction between integers and floating point numbers.

42   // a number
42.1 // still a number

They support the usual arithmetic infix operators:

-x // unary negation
x + y // addition
x * y // multiplication
x - y // subtraction
x / y // division
x % y // modulo

Strings

⚠️ Dust doesn't parse escape characters in strings yet

Strings are created using " characters and are immutable

"hello!"

Nil

nil (also called "unit" or "empty tuple" in other languages) is a value that can either be used as a return value for functions that do not return any meaningful values (e.g. print()) or couldn't return any possible values for a certain input. There is only one instance of nil (meaning that nil == nil)

Tuples

Tuples are immutable sequences of data. Currently only 2 and 3 elements tuples are supported. A possible use case is to return multiple values from a function

#(a, b)
#(a, b, c)

Lists

Lists are internally represented as linked lists.

// Empty list
[]

// The cons operation allows to prepend in O(1) time an head to a list, e.g.
[1, ..[2, ..[3, ..[]]]] // => [1, 2, 3]

// But there's also a syntax sugar to do the former
[1, 2, 3]

You can mix those syntaxes as long as the `..` comes last:
[1, 2, ..tl]

Maps

Maps are key-value dictionaries. Only strings are currently supported as keys.

// Empty map
#{ }

// a map with two entries
#{ "x" => 0, "y" => 1 }

let m = #{ "x" => 0 }
// `cons` a map into another
#{ "y" => 1, ..m } // => #{ "x" => 0, "y" => 1 }

// entries can also be computed:
let key = "x";
#{ key => 42 } // => #{ "x" => 42 }