Skip to content

Data Types

mar edited this page May 21, 2023 · 3 revisions

Basic types in harlock

// Values and variables
1                           # integers
"string test"               # strings
true                        # booleans
[1, 2, 10]                  # arrays
{key2: val2, key1: val1}    # maps
set(1,2 10, 20)             # sets
var err = error("error!")   # errors
var ex = 12                 # variables
// this is a comment        # comments

Integer values and operations

var normal = 12
var hex = 0xff
10 + 1
10 - 1
10 * 2
10 / 2
10 % 2
10 == 10
10 != 11
10 < 2
10 > 2
10 <= 2
10 >= 2
0xfe & 0x01
0xfe | 0x01
0xfe << 1
0xfe >> 1
~0xff
hex(12)

Booleans

var t = true
var f = false
true && false
true || false
true == false
true != false

Strings

var s = "test string"
var s = 'test string'
s == "test string"
s != "test strings"
len(s) == 11
from_hex("FF0102") == [255, 1, 2]

Arrays

var arr = [1, 2, 3]
arr[0] == 1
arr.push(4)
arr.pop()
arr.slice(0, 1)
contains(arr, 1)

Maps

var m = {"test": value, 1: 23}
len(m) == 2
m["test"] = value
m.set("new", 12)
m.pop("new")
contains(m, "test")

Sets

var s = set(1, 3, 5, 4)
var s2 = set([1, 2, 4, 3, 4])
s.add(10)
s.remove(3)
contains(s, 1)

Errors

var err = error("error!")
var div = func(x, y) { 
  if y == 0 {
    ret err("division by zero")
  } 
  ret x/y
}
var res = try div(1, 0)
Clone this wiki locally