Sunbird is a simple, interpreted, dynamically typed language.
Single line comments start with //
and continue to the end of the line.
// This is a single line comment
Block comments are enclosed within /* ... */
and can span multiple lines.
/*
This comment
spans multiple
lines
*/
In Sunbird you declare variables using the var
keyword:
var foo = "Hello, World!"
Sunbird supports all the basic data types:
var str = "hello!" // string
var int = 10 // integer
var float = 3.14 // float
var bool = true // booleans
var foo = null // null
Arrays are an ordered list of elements of possibly different types identified by a number index. Each element in an array can be accessed individually by their index. Arrays are constructed as a comma separated list of elements, can contain any type of value, and are enclosed by square brackets:
var arr = [1, "sunbird", 10, 2.2]
To get a value from an array you use the bracket notation:
arr[0]
Negative indices can be used to access elements from the end of the array:
arr[-1] // Returns the last element from the array
Functions in Sunbird are defined using the func keyword:
var add = func(a, b) {
return a + b
}
You can also skip the return
:
var add = func(a, b) {
a + b
}
Functions can be called like this:
var result = add(10, 5) // 15
Sunbird supports if
, else if
, and else
statements:
var x = 5
var y = 10
if x > y {
println("x is greater than y")
} else if x == y {
println("x is equal to y")
} else {
println("x is less than y")
}
A for
loop is used to execute a block of code multiple times.
for i = 0; i < 10; i = i + 1 {
println("This code will run 10 times")
}
Embedded function calls can get messsy and hard to follow. For example:
var result = foo(bar(baz(another_func(data))))
in that case you can use the pipe operator:
var result = data |> another_func |> baz |> bar |> foo
Note: documentation is work in progress