© Jørgen Steensgaard-Madsen, Copenhagen, 2006
Mutable variables                                                  
 
   

A variable may be assigned a value, which may be subsequently be read and used in expressions. This is the most elementary example of an object with state, or a finite state machine. Readers are assumed to be familiar with this notion from other languages, although the analogy with objects and finite state machines may not be so.
The general pattern for use of variables in Howard languages can be summarised as
{ var x;  ... x := x+1; ...; x *= 8; ... }

Only one type of values may be stored in a variable, but which one is inferred from use of the variable.
Several of the general mechanism of Howard languages are used to support variables:

Operators

[ += OF lval,rval {rval+rval,lval:=rval}(lval,rval) : rval ]
[ -= OF lval,rval {rval-rval,lval:=rval}(lval,rval) : rval ]
[ *= OF lval,rval {rval*rval,lval:=rval}(lval,rval) : rval ]
[ /= OF lval,rval {rval/rval,lval:=rval}(lval,rval) : rval ]
[ %= OF lval,rval {rval%rval,lval:=rval}(lval,rval) : rval ]
[ |= OF lval,rval {rval|rval,lval:=rval}(lval,rval) : rval ]
[ &= OF lval,rval {rval&rval,lval:=rval}(lval,rval) : rval ]
[ ^= OF lval,rval {rval^rval,lval:=rval}(lval,rval) : rval ]

These operators are inspired by the C programming language: x *= y assigns x*y to x - formally x := x*y - and requires that * is defined for the type of values stored in x. The other operators are characterised similarly.

Operation overview

An operation signature associates a name with a list of clause descriptions and possibly a result type. An application of an operation is called a command.
Function arguments are simple examples of clauses, as are the branches of a conditional command. In more complex cases a clause may be the scope of some descendants of the command operation. Different clauses will usually have different descendants.
A clause description is a signature itself: it associates a name of the clause with a list of signatures of descendants. Detailed information about the language of signatures and commands will have to be found elsewhere.

Semantics


[ var OF w,rvalue[Scope OF lvalue ... : w] : w ]



Variables are described as objects that requires two types for instantiation: rvalue being the type of values that can be stored and w which is the type of the value computed by means of the variable (the type of its continuation, if that means anything to you).
The Scope clause constitutes the scope of object members, i.e. the means provided to manipulate the state of the object, here the value stored in the variable: values can be assigned and read in such a scope, but not elsewhere.
Clause:   Scope of operation var
Type lvalue is locally bound, i.e. is an abstract types. Each instantiation of a variable introduces a type that cannot be confused with others. Similarly, it introduces a unique meaning and associate it with the assignment operator. Use of the possibly overloaded assignment operator requires that a unique meaning be found, and the lvalue type is used for this purpose.

Semantics

[ arrayvar OF rvalue,W
     (n:int)
     [Operations OF lvalue ... : W] : W ]

An array of variables has entries that correspond to simple variables, all capable of storing a value of the same type. Consequently, members require a number to select an entry but otherwise correspond to the members of a simple variable.
The totality of values stored in an array can be used to build a value of array-type, i.e. a structured value with components that can be accessed by indexing, just as the elements of the array of variables. However, note that a value of array-type is not mutable.
Given a value of appropriate array-type it can be used to set values to corresponding entries in an array of variables.
Clause:   Operations of operation arrayvar
Type lvalue is locally bound, i.e. is an abstract types as for simple variables. Where simple variables have simple members, array variables have member functions, but the general design is the same:

Contents

·Demo language
Implementation tool
Copyrights


General properties
Applications
·Contributions
Installation


Somefix operators
Statements
Predefined type operators
·Mutable variables
Functions for mathematics
File operations
Processes and connections
Misc. utilities
New type operators
Top-level entities



File translated from TEX by TTH, version 3.33.
On 18 Oct 2006, 16:47.
SourceForge.net Logo