🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #115

Dynamic arrays in Modula-2?

#115
From: aubrey mcintosh
Date: Thu, 09 Apr 1992 22:57
49 lines
1855 bytes
> From: dmb@srl03.usl.edu (David M. Brumley)
> Date: 9 Apr 92 22:57:46 GMT
> Message-ID: <DMB.92Apr9165746@srl03.usl.edu>

> How does one express dynamic allocation of single and
> multi-dimensional arrays in Modula-2?  How does one pass a dynamically
> allocated multi-dimensional array as an argument to a procedure?
> 
> My references on Modula-2 lead me to believe that this elementary
> operation is difficult or impossible to solve elegantly or portably in
> Modula-2.


I have a general matrix arithmetic package that may interest you.  It may
be ftp-ed from 
     titania.mathematik.uni-ulm.de:
     /pub/soft/oberon/ethz/contrib/Matrix/Matrix.tar.Z

This package was initially written PIM2 conformant under the Logitech 
compiler, and with minor changes was ported to the Oberon operating 
system. It should read easily for a Modula-2 programmer.

Some relevant code is:

  TYPE
    Real = RECORD
      value: REAL;
      lastPosition: INTEGER;
      exact: BOOLEAN;
    END ;

	TYPE
		Matrix* = 
			RECORD
				dimensions* : ARRAY 2 OF INTEGER;
				values*		: POINTER TO ARRAY Maxarray OF Natural.Real;
			END;

	PROCEDURE Create*
					(		frows, fcolumns : INTEGER;
						VAR result : Matrix );
	BEGIN
		result.dimensions[0] := frows;
		result.dimensions[1] := fcolumns;
		SYSTEM.NEW( result.values, frows * fcolumns * SIZE( Natural.Real ) )
	END Create;
-- 
Aubrey McIntosh  /  Chemistry  /  University of Texas  /  Austin, TX 78712
..another Gaelic learner...
Technical Details
Message-ID: <70410@ut-emx.uucp>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu
From: mcintosh@ccwf.cc.utexas.edu (aubrey mcintosh)
Newsgroups: comp.lang.modula2
Subject: Dynamic arrays in Modula-2?
Message-ID: <70410@ut-emx.uucp>
Date: 9 Apr 92 22:57:46 GMT
Sender: news@ut-emx.uucp
Organization: University of Texas, chemistry dept.
Lines: 49