စံကား

09Lists

List mistakes

The mistakes lists make possible, and how Zaka catches each one.

A cell number outside the list

A list of 3 cells has cells 0, 1 and 2. A cell number past them is a mistake. Here the number sits in a variable, and the compiler still works out that it is 3:

စံကားZK0710

Expected error

error[ZK0710]: offset 3 is past the end of a block of 3 elements

With --mem-check warn, or Warn in the Explorer, the program runs and the VM stops it, with the range the list allows:

စံကား

Expected output

the program stopped: cell 3 is outside the list, whose cells run from 0 to 2

When the number comes from input, the VM's check is the one that catches it. When the number is written in place, as a constant, Zaka reports it with another code, in each mode. Counting from 1 starts at 1, not 0:

စံကားZK0603

Expected error

error[ZK0603]: cell 0 is outside the list, whose cells run from 1 to 3

A cell number that takes a sum

The cell number takes the whole operator expression after အကွက်, so this reads cell ၁ + ၂, which is outside the list:

စံကားZK0603

Expected error

error[ZK0603]: cell 3 is outside the list, whose cells run from 0 to 2

Write (ကိန်းများ ၏ အကွက် ၁) + ၂ to add 2 to cell 1.

A literal with the wrong count

စံကားZK0419

Expected error

error[ZK0419]: the kind holds 3 cells, but the list has 2

A blank list with no kind

စာရင်းအလွတ် takes its kind from where it stands. Standing alone, it has none:

စံကားZK0420

Expected error

error[ZK0420]: a blank list needs a list kind from its place

A list kind with no count

A kind with no count needs a value that gives one:

စံကားZK0421

Expected error

error[ZK0421]: this list kind has no cell count, and nothing here gives one

Cells of a value that is no list

စံကားZK0422

Expected error

error[ZK0422]: isize is not a list, so it has no cells

The cell count, written as two words

အကွက်အရေအတွက် is one word. Written with a space, အကွက် အရေအတွက် reads as the cell numbered with a variable named အရေအတွက်.

Hands on

  • Read cell 5 of a list of 5 cells through a variable, and read the message.
  • Read the same cell with a constant number, and compare the two messages.

Next: Natural Zaka.