Record

From Mesham
Revision as of 21:29, 10 January 2010 by Polas (talk | contribs) (Created page with '== Syntax == record[name<sub>1</sub>,type<sub>1</sub>,name<sub>2</sub>,type<sub>2</sub>,.....,name<sub>d</sub>,type<sub>d</sub>] == Semantics == The ''record'' type allows the…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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, .

Example

var complex : record["r",Float,"i",Float];
var person: record["name",String, "age",Int, "gender",Char];
var a:array[complex,10];
(a#1).i:=22.3;
var b:complex; 
var me:person;
me.name:="nick";

In the above example, complex (a complex number) is a record with two float elements, i and r. The variable b is defined as a complex number and a as an array of these numbers. The variable me is of type person.