The Basics

Types

Boa has a variety of types to use in your code. These different types are utilized for varying tasks that may be needed in your code.

The following types are available:

NUMBER

The NUMBER type is just literally a double. There is no boolean type, but the value 1 acts as true and 0 is false. Please note that the NUMBER type is the only type to use the '^' operator.

>>> 1
1
>>> 1.5
1.5
>>> 1 + 1.5 // Addition operator
2.5
>>> 1 - 1.5 // Subtraction operator
-0.5
>>> 12 * 5 // Multiplication operator
60
>>> 12 / 6 // Division operator
2
>>> 5 ^ 2 // Exponent operator
25

STRING

The STRING type is a string of characters.

>>> "Hello World!"
Hello World!
>>> "Hello World" + "!" // Addition operator
Hello World!
>>> "Hiya" * 3 // Multiplication operator
HiyaHiyaHiya
>>> "Hello World!" ? 6 // Get the nth character
W

LIST

The LIST type is a list of any type of values.

>>> [1, 2, ["Nested List!", 1], {}]
[1, 2, [Nested List!, 1], {}]
>>> [1, 2, ["Nested List!", 1], {}] + "hello" // Push back a value
[1, 2, [Nested List!, 1], {}, hello]
>>> [1, 2, ["Nested List!", 1], {}] - 2 // Remove value by index
[1, 2, {}]
>>> [1, 2] * [3, "four"] // Extend the list by another
[1, 2, 3, four]
>>> [1, 2] ? 1 // Get the nth index
2

MAP

MAPs store multiple key value pairs of any type.

>>> {"key1": 1, 2: "key2", "key3": ["Nested List!", 1]
{key1: 1, 2: key2, key3: [Nested List!, 1]}
>>> {"key1": 1} + ["key", "value"] // Adding a key value pair to the map
{key1: 1, key: value}
>>> {"key1": 1} - "key1" // Removing a pair using the key
{}
>>> {"key1": 1} ? "key1" // Get a value by key
1

Variables

Variables are used to store values. Variables are not type specific and are dynamically typed. Variables are defined by a name, followed by an equal sign and then an expression. name = expression

>>> x = "Hello" // String
Hello
>>> x = 1 // Number
1
>>> x = false // true: 1, false: 0
0
>>> x = null // Null is just 0
0
>>> x = [] // List
[]
>>> x = {} // Map
{}

Accessing variables

Variables can be accessed by using the name you set for them. They can be accessed in expressions.

>>> x = "Hello" // Initializing the variable
Hello
>>> x // Accessing the variable
Hello
>>> y // Accessing a variable that hasn't been defined

Traceback (most recent call last):
  File <stdin>, line 1, in <program>
RuntimeError: y is not defined

y
^