//-------------------------------------------------------------------- // Example of 2 dimensional array constructors, no sparse initial values //------------------------------------------------------------------- main module ARCONST2 use TEXTIO declare XRANGE is 1..5 YRANGE is 1..6 Y is array [YRANGE] of integer XY is array [XRANGE] of Y CGRID = XY ( [1] : Y ( [1..1] : 10, [2..6] : 3), [2] : Y ( [1..2] : 20, [3..6] : 3), [3] : Y ( [1..3] : 30, [4..6] : 3), [4] : Y ( [1..4] : 40, [5..6] : 3), [5] : Y ( [1..5] : 50, [6..6] : 3) ) GRID : XY GRID_s : static XY GRID_c : XY GRID_cs : static XY GRID_t : XY GRID_ts : static XY GRID_i : XY initially XY ( [1] : Y ( [1..1] : 10, [2..6] : 3), [2] : Y ( [1..2] : 20, [3..6] : 3), [3] : Y ( [1..3] : 30, [4..6] : 3), [4] : Y ( [1..4] : 40, [5..6] : 3), [5] : Y ( [1..5] : 50, [6..6] : 3) ) GRID_is : static XY initially XY ( [1] : Y ( [1..1] : 10, [2..6] : 3), [2] : Y ( [1..2] : 20, [3..6] : 3), [3] : Y ( [1..3] : 30, [4..6] : 3), [4] : Y ( [1..4] : 40, [5..6] : 3), [5] : Y ( [1..5] : 50, [6..6] : 3) ) GRID_ic : XY initially CGRID GRID_ics: static XY initially CGRID enddeclare procedure out_grid ( G: in ref XY ) for XIndex in XRANGE do for YIndex in YRANGE do out_integer (TTY, G [XIndex, YIndex], " ") endfor out_record (TTY) endfor endprocedure GRID := XY ( [1] : Y ( [1..1] : 10, [2..6] : 3), [2] : Y ( [1..2] : 20, [3..6] : 3), [3] : Y ( [1..3] : 30, [4..6] : 3), [4] : Y ( [1..4] : 40, [5..6] : 3), [5] : Y ( [1..5] : 50, [6..6] : 3) ) GRID_s := XY ( [1] : Y ( [1..1] : 10, [2..6] : 3), [2] : Y ( [1..2] : 20, [3..6] : 3), [3] : Y ( [1..3] : 30, [4..6] : 3), [4] : Y ( [1..4] : 40, [5..6] : 3), [5] : Y ( [1..5] : 50, [6..6] : 3) ) GRID_c := CGRID GRID_cs := CGRID GRID_t := table XY ( Y ( [1..1] : 10, [2..6] : 3), Y ( [1..2] : 20, [3..6] : 3), Y ( [1..3] : 30, [4..6] : 3), Y ( [1..4] : 40, [5..6] : 3), Y ( [1..5] : 50, [6..6] : 3) ) GRID_ts := table XY ( Y ( [1..1] : 10, [2..6] : 3), Y ( [1..2] : 20, [3..6] : 3), Y ( [1..3] : 30, [4..6] : 3), Y ( [1..4] : 40, [5..6] : 3), Y ( [1..5] : 50, [6..6] : 3) ) //---------------------------------------------------- tty_line ("dynamic grid assigned from inline constructor") out_grid( GRID ) tty_line ("static grid assigned from inline constructor") out_grid( GRID_s ) tty_line ("dynamic grid assigned from constant constructor") out_grid( GRID_c ) tty_line ("static grid assigned from constant constructor") out_grid( GRID_cs ) //---------------------------------------------------- tty_line ("dynamic grid initialized from inline constructor") out_grid( GRID_i ) tty_line ("static grid initialized from inline constructor") out_grid( GRID_is ) tty_line ("dynamic grid initialized from constant constructor") out_grid( GRID_ic ) tty_line ("static grid initialized from constant constructor") out_grid( GRID_ics ) //---------------------------------------------------- tty_line ("dynamic grid assigned from inline table constructor") out_grid( GRID_t ) tty_line ("static grid assigned from inline table constructor") out_grid( GRID_ts ) endmodule