Arrays and Lists
Although some output languages don't consider there to be a difference between arrays and lists, Budgie defines them as:
Array: A fixed length data structure of a single templated type
List: A variable length data structure of a single templated type
Budgie considers the two to be two different data structures and has mostly separate commands for each.
Arrays
Because arrays are fixed-length, there are very few operations available on them.
Create new arrays with array new
, which takes in the type of array and any number of initial items in the array. For variables, declare the type of the array with array type
, which takes in the type of the array.
Retrieve a single member of an array with array get
, which takes in a name of a container and an integer index.
In C#:
container[1]
In Python:
container[1]
Set a single member of an array with array set
, which takes in a name of an array, an integer index, and a new value.
In C#:
container[1] = "apple";
In Python:
container[1] = "apple"
Get the length of an array with array length
, which takes in a name of an array.
In C#:
In Python:
Generic Arrays
Creating arrays of generic types with the array new generic
and array new generic sized
commands. They're used the same as their non-generic counterparts.
In C#:
In Python:
Lists
Budgie lists are much more flexible than arrays. They can be dynamically resized, added onto one another, and sorted.
Retrieve a single member of a list with list get
, which takes in a name of a container and an integer index.
In C#:
container[1]
In Python:
container[1]
Set a single member of a list with list set
, which takes in a name of a list, an integer index, and a new value.
In C#:
container[1] = "apple";
In Python:
container[1] = "apple"
Creating Lists
Similar to arrays, create a new list with list new
, declare a list type with list type
, and get a list's length with list length
. Add a single item to a list with list pop
, which takes in a name of a list and a new item, or add a full list to another list with list add list
, which takes in the name of an existing list and a second list to add to the existing list.
In C#:
In Python:
Last updated