8.1 Patterns and Variables

In BETA, a descriptor can be given a name. Thereafter, the name becomes a short-hand form for the full description. The association of name and descriptor is written amongst the declarations and is known as a pattern declaration. It has the following syntax:

<pattern-name>: <prefix> <descriptor>

Thereafter, the pattern name or the descriptor can be used interchangeably and the term pattern is used to mean either form. prefix is an optional name of a pattern that pattern-name inherits from.

As we have seen previously, variable declarations are characterized by the @ token:

<variable-names>: @<pattern>

Examples:

POINT: (# X,Y: @real;
 enter (X,Y)  
 exit (X,Y)
 #);

P1,P2: @Point;
P3: @(# X,Y: @real;
enter (X,Y)  exit (X,Y)
      #);

P1 and P2 are considered to be objects of the same class. Note also that case is immaterial in BETA: POINT being the same as PoINt or point.

Thereafter, the following assignments are allowed:

P1 -> p2;
(0,0) -> p1 -> p2 -> p3;

Note that BETA uses structural equivalence in its value assignments and comparisons. This is not as strict as in other languages and assignment is possible between variables of any two patterns with similar enter and exit lists. This was shown above (with identical lists) and if we define another pattern complex with two reals as value, assignment will be allowed between Point and complex objects.

C1: @(# Re,Im: @real;
     enter (Re, Im) 
     exit (Re, Im)
     #);


Libraries Tutorial
© 1994-2004 Mjølner Informatics
[Modified: Thursday October 19th 2000 at 14:10]