Create a two-dimensional array at runtime: Difference between revisions

Component Pascal example added
m (→‎Icon and Unicon: header simplification)
(Component Pascal example added)
Line 318:
 
The <tt>[http://www.lispworks.com/documentation/HyperSpec/Body/m_assert.htm assert]</tt> will allow the user to reenter the dimensions if they are not positive integers.
 
=={{header|Component Pascal}}==
 
An arrays in Component Pascal are started from zero index. No DISPOSE-like procedures because of garbage collection.
 
<lang oberon2>
MODULE TestArray;
(* Implemented in BlackBox Component Builder *)
 
IMPORT Out;
 
(* Open array *)
PROCEDURE DoTwoDim*;
VAR d: POINTER TO ARRAY OF ARRAY OF INTEGER;
BEGIN
NEW(d, 5, 4); (* allocating array in memory *)
d[1, 2] := 100; (* second row, third column element *)
d[4, 3] := -100; (* fifth row, fourth column element *)
Out.Int(d[1, 2], 0); Out.Ln;
Out.Int(d[4, 3], 0); Out.Ln;
END DoTwoDim;
 
END TestArray.</lang>
 
=={{header|Factor}}==
Factor doesn't provide any support for easy access of 2d arrays. But since factor's written in factor, we can just add it and it's just as good :)
Anonymous user