NewList

Statement

Syntax

Declares a list: values kept in order, with one current element. <name>() reads or writes that element.

NewList <name>.<type>()
NewList <name>()
GLOBAL NewList <name>.<type>()
LOCAL NewList <name>.<type>()
<name>()
<name>().<field>

Parts

<name>The list's name, with no sigil. It cannot also be the name of a map.
<type>The type of the elements: a short suffix (.i, .f, .d, .s, .q…), a full name (.integer, .string, .float64), or a TYPE name. Without it, the list holds integers.
<field>A field of the current element, for a list of records: foes().hp = 30.

Good to know

  • A new list is empty and has no current element. Reading or assigning <name>() then stops the program: BASIC list has no current element. Add one first with AddElement().
  • Values are converted to the list's type: an integer list stores 20.9 as 20, and .f is 32-bit (0.1 reads back as 0.10000000149011612). Use .d for full precision.
  • NewList names$() is refused at the first use of names(). Write the type after a dot: NewList names.s().
  • += on the current element and INC l() compile into a program that does not start. Write l() = l() + 5.
  • NewList again on the same name makes a new, empty list. A NewList inside a FUNCTION belongs to that call.
  • In a program with a DO … LOOP, a FUNCTION does not see a list declared above DO (… is not defined). Declare it with GLOBAL NewList.

Example

NewList scores.i()AddElement(scores())scores() = 10AddElement(scores())scores() = 30FirstElement(scores())AddElement(scores())scores() = 20.9FOREACH scores()  Console(Str(ListIndex(scores())) + ": " + Str(scores()))   ' 0: 10, then 1: 20, then 2: 30NEXTConsole(Str(ListSize(scores())))   ' 3
In the manual : Arrays, lists and maps