Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (44 sloc) 1.58 KB
description
Variables in Caboose.

Variables

Variables consist of many data types:

Type Example
string "hello", 'world'
number 100, 1.0
nil nil
bool true, false
list ["hello", 1, true, nil]
dict {"hello": 1, "world": false}

Variable Assignment

In Caboose the syntax for variable assignment is var <identifier> = <value>;, where <identifier> is a name containing only alphabetical characters and underscores, and <value> is a valid data type.

Once you have defined a variable, you no longer need to use the var keyword to update it. Variables can also change their type at runtime.

Examples

{% code-tabs %} {% code-tabs-item title="example_variable_assignment.cb" %}

var someNumber = 10;
var someString = "hello";
var someOtherString = 'hello';
var someBoolean = true;
var someFalseBoolean = false;
var someNilValue = nil;
var someOtherNilValue; // Variables declared without a value are set to nil
var someList = [1, 2, "hi", 'hi', nil, true, false]; // Lists can hold any value
var someDict = {"key": 10, "key1": true, "key2": [1, "2", false], "key3": {"1": 2}}; // Dictionaries must have a string key, but can hold any value

{% endcode-tabs-item %}

{% code-tabs-item title="example_variable_reassignment.cb" %}

var someNumber = 10;

someNumber = someNumber + 1;

{% endcode-tabs-item %}

{% code-tabs-item title="example_variable_type_change.cb" %}

var someVariable = 10;
someVariable = "Some text"; // This is perfectly valid

{% endcode-tabs-item %} {% endcode-tabs %}

You can’t perform that action at this time.