Skip to content

Reference Type

CD2 edited this page Feb 8, 2023 · 4 revisions

Reference

is an array. You can refer to anything referenced by a reference or a list. Prefixing the referenced type name with / makes it read-only.

^int a.new(10); // create an array of 10 ints

a = a[1..9]; // slice from 2nd to 9th

a.new(0); // create a new array for 0

// However, an array of length 0 does not have a mutex

ref c = a; // Dynamic type reference. A reference type that points to a reference type cannot be assigned

int id = c.typeid; // same value as typeidof(int)

index size = c.typesize; // same value as sizeof(int)

c.cast(a=); // Cast to static type. cannot operate on dynamic type

// return false if the cast failed

List

An array that can be appended. You can refer to anything referenced in the list.

%int a.new(10); // create an array of 10 ints that can be appended

a.new[10] = 0; // set length to 11 and assign 0 to 11th

a.new[-1] = 0; // increment the length by 1 and assign 0 to the last element

a.new[-2] = 0; // Increase the length by 2 and assign 0 to the penultimate element

a .= 0; // append 0

a .= a[0..2]; // append the first and second elements

%int b = a; // refers to the same thing as a

// However, assigning a list of length 0 has the same meaning as b.new(0)

list c = a; // dynamic type list. Usage is the same as dynamic type reference

Clone this wiki locally