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.
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
|integer||7, -4, 0x4FFC, 2x101101|
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.
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 *)
BETA has two build-in control structures: if and for, both having two forms. The simple if imperative with one boolean expression:
(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:
(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):
<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:
L: (# leave L; restart L #)
In general any imperative can have a label:
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.
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.
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 *)
Examples of dynamic reference variables are:
i: ^integerObject p: ^A
Assignments between dynamic references can be done using the reference operator '' (read box):
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.
In BETA it is possible to declare a repetition of static (simple types) or dynamic references. A repetition is declared like:
R:  @integer (* repetition of 10 static references *) P:  ^A (* repetition of 10 dynamic references *) R -> i (* value assignment *) P -> x (* reference assignment *) RR:  @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.
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; #)
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]