Skip to content
On this page

Lists

There is no difference in terms of behavior between GreyScript and MiniScript.

The third basic data type in MiniScript is the list. This is an ordered collection of elements, accessible by index starting with zero. Each element of a list may be any type, including another list.

Source: MiniScript manual

Operations

gs
// concatenation
a = ["test"] + ["bar"] // concatenates two lists - results in ["test", "bar"]

// multiplication
a = ["test"] * 2 // repeats items x amount of times - results in ["test", "test"]

// division
a = ["test", "test"] / 2 // slices items by length - results in ["test"]

// equality
a = ["test"] == ["test"] // returns true (1) if two maps are equal otherwise false (0) - results in true (1)

// inequality
a = ["test"] != ["test"] // returns true (1) if two maps are inequal otherwise false (0) - results in false (0)

// index
a = ["test", "bar"][1] // get item at index - results in "bar"

Isa

Beside of using typeof, to determine if a variable is a list, you can also use isa.

gs
myVariable = []

print(myVariable isa list) // prints 1

Extend type

It is possible to extend your own methods to the list type.

gs
list.toString = function
  return str(self)
end function

print((["test", "bar"]).toString()) // prints ["test", "bar"]