Record

From Mesham
Jump to navigationJump to search

Syntax

record[name1,type1,name2,type2,.....,named,typed]

Semantics

The record type allows the programmer to combine d attributes into one, new type. There can be any number of names and types inside the record type. A record type is very similar to a typedef structure in C. To access the member of a record use the dot, .

Default typing

Example

function void main() {
   typevar complex ::= record["r",Float,"i",Float];
   var a:array[complex, 10];
   var number:complex;
   var pixel : record["r",Int,"g",Int,"b",Int];

   a[1].r:=8.6;
   number.i:=3.22;
   pixel.b:=128;
};

In the above example, complex is declared as a type variable to be a complex number. This is then used as the type chain for a which is an array and number. Using records in this manner can be useful, although the other way is just to include directly in the type chain for a variable such as declaring the pixel variable. Do not get confused between the difference between complex (a type variable existing during compilation only) and pixel (a normal data variable which exists at runtime.) In the last two lines assignment occurs to the declared variables.

Since: Version 0.41b