2 Basic Constructs

The most fundamental elements of BETA are objects and patterns. This section describes the basic patterns and values, simple assignments, control structures, variable declarations, repetitions and patterns used as composite types.

2.1 Simple Types and Values

The simple types (or also called basic patterns) are integer, boolean, char, and, real. The following table shows the simple types with examples of values, including text constant. Notice, that text is not a simple type in BETA, but a pattern defined in the basic BETA environment called betaenv.

Type Value
integer 7, -4, 0x4FFC, 2x101101
boolean true, false
char 'c'
real 3.141, -1.234E3
text constant 'abc'

2.2 Simple Static Variables

In BETA, a static variable (also called a static reference) is declared like:

i: @integer;
r: @real;

Variables of the simple types can only be declared static, see below for dynamic references.

2.3 Simple Assignments

2.3.1 Value assignment

Simple value assignments in BETA goes left to right:

2 -> i         (* assign the value 2 to i *)
i -> j         (* assign the value of i to j *)
i*j -> k       (* assign the value of i*j to k *)
(i,j) -> (x,y) (* assign the value of i to x and 
                *        the value of j to y 
                *)

2.4 Control Structures

BETA has two build-in control structures: if and for, both having two forms. The simple if imperative with one boolean expression:

2.4.1 if

(if <expression> then 
    <imperatives>
 else
    <imperatives>
if)

and the if with several alternatives:

(if <expression>
 // <expression> then <imperatives>
 // <expression> then <imperatives>
 else
   <imperatives>
if)

where // means equals.

The simple for imperative just iterates a given number of times:

2.4.2 for

(for <expression> repeat <imperatives> for)

but the for imperative may implicitly declare an iteration variable, only available inside the for loop, by:

(for <variable>: <expression> repeat <imperatives> for)

The for loop always starts in 1 and stops at <expression>. The loop can be terminated or restarted using labels, see below.

The following BETA code is a general object-descriptor (or descriptor for short):

2.4.3 descriptor

<declarations>
enter <enter-list>
do <imperatives>
exit <exit-list>

A descriptor consists of type and variable declarations, an enter part for parameters (enter <enter-list>), a do-part for the action (do <imperatives>), and finally an exit part for the results (exit <exit-list>). All elements are optional.

A descriptor can be labeled, and the descriptor can be restarted and/or left using the label:

2.4.4 labeled descriptor

L: (#  leave L; restart L #)

In general any imperative can have a label:

2.4.5 labeled imperative

L: <imperative>
L: (if   leave L   if)
L: (for  leave L  for)

leave L implies that control is transferred to immediately after the labeled imperative/descriptor. restart L implies that control is transferred to immediately before the labeled imperative/descriptor.

2.5 Static and Dynamic Variables

2.5.1 Reference attributes

In BETA variables are two examples of reference attributes - static references that constantly denote the same object, and dynamic references that may denote different objects.

2.5.2 Static Reference

Examples of static reference variables are:

i: @integer (* i refers to a simple type: integer *)
p: @A       (* an instance of A is automatically generated and
             * p always refers to this object *)
s: @(#  #) (* an instance of (#  #) is automatically generated 
             * and s always refers to this singular object *)

2.5.3 Dynamic reference

Examples of dynamic reference variables are:

i: ^integerObject
p: ^A

Assignments between dynamic references can be done using the reference operator '[]' (read box):

2.5.4 Reference assignment

p1[] -> p2[]  (* reference assignment *)

Dynamic reference variables are initially NONE i.e. refers to nothing. Objects can be created using the new operator '&':

&A[] -> p[]  (* create an instance of A and assign the reference
              * to p *)

It is illegal to declare dynamic references to simple types:

i: ^integer (* ILLEGAL *)
r: ^real    (* ILLEGAL *)

Instead use integerObject, charObject, booleanObject, or realObject defined in the Mjølner System basic betaenv environment.

2.6 Repetitions

In BETA it is possible to declare a repetition of static (simple types) or dynamic references. A repetition is declared like:

R: [10] @integer  (* repetition of 10 static references *)
P: [10] ^A        (* repetition of 10 dynamic references *)
R[1] -> i         (* value assignment *)
P[1][] -> x[]     (* reference assignment *)
RR: [1] @integer  (* repetition of 1 static reference *)
R -> RR           (* repetition assignment:
                   * all values from R is copied into RR
                   * RR is automatically extended if needed
                   *)
R.range           (* the size of the repetition *)
n -> R.extend     (* extends the repetition with n elements *)
n -> R.new        (* allocates a new repetition with n elements *)

The range of a repetition is 1 to R.range, thus repetitions always start with 1.

2.7 Composite Types (Records)

Using the object-descriptor it is possible to declare composite types:

point:  (# x,y: @integer #) (* point is a composite type 
                             * consisting of two integers *)
p: @point    (* static declaration of a point *)
p.x          (* remote access to x *)
circle:      (* composite type using simple and composite types *)
  (# center: @point; 
     radius: @integer;
  #)

2.7.1 Pattern

The declaration of point and circle above is in general called a pattern declaration. The pattern will be described in details in the following sections.


BETA Language Introduction
© 1994-2002 Mjølner Informatics
[Modified: Saturday October 21st 2000 at 18:34]