Referencerecord

From Mesham
Revision as of 18:24, 13 January 2013 by Polas (talk | contribs)
Jump to navigationJump to search

Syntax

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

Semantics

The record type may NOT refer to itself (or other records) where as reference records support this, allowing the programmer to create data structures such as linked lists and trees. There are some added complexities of reference records, such as communicating them (all links and linking nodes will be communicated with the record) and freeing the data (garbage collection.) This results in a slight performance hit and is the reason why the record concept has been split into two types.

Default typing

Currently communication is not available for reference records, this will be fixed at some point in the future.

Example

#include <io>
#include <string>
typevar node;
node::=referencerecord["prev",node,"Int",data,"next",node];
var head:node;
head:=null;
var i;
for i from 0 to 9 {
   var newnode:node;
   newnode.data:=i;
   newnode.next:=head;
   if (head!=null) head.prev:=newnode;
   head:=newnode;
};

while (head != null) {
   print(itostring(head.data)+"\n");
   head:=head.next;
};

In this code example a doubly linked list is created, and then its contents read node by node.

Since: Version 0.5