Mutable Arrays

Create mutable arrays with square brackets [...]. Modify elements or add/remove items:

set arr = [10, 20, 30]
print(arr)
print(arr.length)

set x = arr[0]
arr[0] = 99
print(arr[0])

push(arr, 40)
set last = pop(arr)
print(arr)

Array Methods

  • .length — Get the number of elements
  • [index] — Access or modify element
  • push(array, value) — Add element to end
  • pop(array) — Remove and return last element

Immutable Arrays

Create immutable arrays with #[...]. You can read elements but cannot modify them:

set frozen = #[1, 2, 3]
print(frozen)
print(frozen.length)
print(frozen[1])

Immutable arrays are useful for data that should not change. Attempting to modify will cause an error.

Objects

Create objects with key-value pairs using curly braces {...}:

set user = { name: "Michael", age: 27 }
print(user)
print(user.name)
print(user.age)

user.age = 18
user["name"] = "Arda K"
print(user)

Accessing Properties

  • obj.key — Dot notation (preferred)
  • obj["key"] — Bracket notation

Object Methods

rmv(user.name)
print(user.name)

Use rmv() to delete a property. Accessing a missing property returns null.

Deep Equality

Arrays and objects are compared by value, not reference:

set a = [1, 2]
set b = [1, 2]
if (a == b) {
    print("Equal!")
}

set obj1 = { x: 1, y: 2 }
set obj2 = { y: 2, x: 1 }
if (obj1 == obj2) {
    print("Equal!")
}

Mutable and immutable arrays compare differently. Object property order doesn't matter for equality.

Iteration

Use for-in loops to iterate over arrays and objects:

Array Iteration

set items = [10, 20, 30]
for item in items {
    print(item)
}

Object Iteration

set user = { name: "Kria", age: 5 }
for key, value in user {
    print(key)
    print(value)
}

Arrays provide individual elements; objects provide both key and value.