Skip to content

Basic Features

cjkenn edited this page Feb 6, 2021 · 4 revisions

Basic Sif Features

Types

sif supports the following primitive types:

  1. Numbers. All numbers are represented by the f64 type in rust. Thus, any number if a 64-bit floating point number
  2. Strings. sif strings wrap the String type in rust.
  3. Boolean. Like strings, bools wrap the bool rust type.

Variables of these types can be declared using the var keyword:

var str = "string";
var num = 10;
var flo = 10.4;
var b = false;

Arrays and tables are also available. Arrays are really like vectors, and can grow dynamically. Tables are hashmaps, and can also grow dynamically. These can be declared as follows:

var arr = [1,2,3];
arr[0] = 0;
var first = arr[0]; # 0

var tbl = [[
  y => "y",
  ten => 10
]];
var y = tbl.y; # "y"

Control Flow

if-elif-else structure:

if true || false {
  var t = 0;
} elif true && true {
  var t = 1;
} elif false || false {
  var t = 2;
} else {
  var t = 3;
}

for loops:

var g = [1,2,3];
var x = 0;
for idx, val in g {
  x = x + val;
}
# x = 6

Builtin functions

There is a small stdlib of functions to use in sif. To call a std function, use the @ token:

var x = 10;
@print(x); # 10

Clone this wiki locally