
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

declare
  %% Read width and height from stdin
  class TextFile from Open.file Open.text end
  StdIn = {New TextFile init(name:stdin)}
  Width = {String.toInt {StdIn getS($)}}
  Height = {String.toInt {StdIn getS($)}}
  %% create array
  Arr = {Array.new 1 Width unit}
in
  for X in 1..Width do
     Arr.X := {Array.new 1 Height 0}
  end
  %% set and read element
  Arr.1.1 := 42
  {Show Arr.1.1}