Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Type Sample Tuple

WiP.TypeSampleTuple History

Hide minor edits - Show changes to output

2010-04-14 23:58 by benjk -
Deleted lines 43-47:


(* literal assignment *)

CONST [{}] allowValueConstructors = TRUE; (* this seems to be redundant *)
2010-04-13 05:30 by benjk -
Changed line 1 from:
[@DEFINITION MODULE SampleVector;
to:
[@DEFINITION MODULE SampleTuple;
2010-04-13 05:30 by benjk -
Changed line 3 from:
(* Sample definition of a tuple type *)
to:
(* Sample definition of a vector derived tuple type, all components are the same *)
2010-04-13 05:29 by benjk -
Added lines 1-70:
[@DEFINITION MODULE SampleVector;

(* Sample definition of a tuple type *)


FROM FileIO IMPORT File; (* required for IO *)


(* component type *)

TYPE ComponentType IS REAL; (* arbitrary numeric type *)


(* SampleTuple type *)

TYPE
    SampleTuple = OPAQUE RECORD ("V-Type")
        capacity : CARDINAL;
        values  : ARRAY capacity OF ComponentType;
    END;


(* cardinality *)

PROCEDURE [HIGH] highestComponentIndex ( t : SampleTuple ) : CARDINAL;


(* constructor *)

PROCEDURE Tuple ( items : CARDINAL; VARIADIC v[items] OF c : ComponentType ) : SampleTuple;
(* constructs a tuple from a value list *)


(* accessor *)

PROCEDURE [.] component ( n : CARDINAL; t : SampleTuple ) : REAL;
(* Returns the value of the n-th component of tuple t *)


(* mutator *)

PROCEDURE [!] setComponent ( n : CARDINAL; VAR t : SampleTuple; c : ComponentType );
(* Overwrites the value of the n-th component of tuple t with c *)


(* literal assignment *)

CONST [{}] allowValueConstructors = TRUE; (* this seems to be redundant *)


(* monadic arithmetic operations *)

PROCEDURE [ABS] abs ( t : SampleTuple ) : SampleVector;


(* relational operations *)

PROCEDURE [=] isEqual ( t1, t2 : SampleTuple ) : BOOLEAN;


(* IO operations, bound to READ, WRITE and WRITEF *)

PROCEDURE Read( infile : File; VAR t : SampleTuple );

PROCEDURE Write( outfile : File; t : SampleTuple );

PROCEDURE WriteF( outfile : File; fmtStr : ARRAY OF CHAR;
                  items : CARDINAL; VARIADIC v[items] OF t : SampleTuple );

END SampleTuple.@]