Skip to content

Array Operators

Michael Wang edited this page Feb 4, 2022 · 2 revisions

There are two principle operators in regards to arrays: Getting an index, a binary operator; and setting an index, a ternary operator. Most operators in SuperForth are very C-like.

Getting a Length

To access an array's length, use the # operator. It's a unary operator that takes an array operand, and returns it's length as an integer;

array<int> array = new int[23];
int len = #array; //is 23

Getting an Index

To access an array's elements, place the array value followed by the index value encapsulated in brackets. The following example demonstrates getting an index from an array.

array<int> array = range(1, 100, 2);
int i = 0;
while(i < #array) {
  int access = array[i]; 
}

Setting an Index

To set an array, place the arrays value followed by the index value encapsulated in brackets then a set token followed by a the value you want to set with.

Clone this wiki locally