31 lines
968 B
Plaintext
31 lines
968 B
Plaintext
prompt = proc (s: string) returns (int)
|
|
stream$puts(stream$primary_output(), s)
|
|
return(int$parse(stream$getl(stream$primary_input())))
|
|
end prompt
|
|
|
|
start_up = proc ()
|
|
po: stream := stream$primary_output()
|
|
|
|
% Ask for width and height
|
|
width: int := prompt("Width? ")
|
|
height: int := prompt("Height? ")
|
|
|
|
% Create an array of arrays.
|
|
% In order to actually create separate arrays, rather than repeating
|
|
% a reference to the same array over and over, fill_copy must be used.
|
|
arr: array[array[int]] :=
|
|
array[array[int]]$fill_copy(1, width, array[int]$fill(1, height, 0))
|
|
|
|
% Set a value
|
|
x: int := 1+width/2
|
|
y: int := 1+height/2
|
|
arr[x][y] := 123
|
|
|
|
% Retrieve the value
|
|
stream$putl(po, "arr[" || int$unparse(x) || "][" || int$unparse(y)
|
|
|| "] = " || int$unparse(arr[x][y]))
|
|
|
|
% The array will be automatically garbage-collected once there
|
|
% are no more references to it.
|
|
end start_up
|