## 1.3 Basic Patterns

### 1.3.1 Simple types

Betaenv contains definitions of the basic patterns char, integer, real, boolean, true and false that are predefined in the BETA language (i.e. built-in data types). These patterns are self-assignable. This means an integer object can be assigned to another integer object, a char object can be assigned to another char object etc.

For efficiency reasons, the usage of the basic patterns char, integer, real, boolean, true and false is somewhat restricted, compared with all other patterns in the system. These restrictions are:

• They cannot be used as superpatterns to other patterns. E.g. subInteger: integer(# ... #) is illegal.
• Dynamic references to instances of these basic types cannot be obtained. E.g. var[] -> ... is illegal if var is an instance of one of these basic patterns.
• Dynamic references to basic patterns cannot be declared. E.g. var: ^integer is illegal.

True object oriented patterns for integers, characters, reals and booleans are also part of the system (see later). However, using those patterns impose an execution overhead compared with the basic patterns.

### 1.3.3 Arithmetical operators

Besides the arithmetical operations: +, -, *, div, and mod and the relational operations: =, <>, >, >=, < and <=, the Min, Max and Abs patterns are defined for integers. The patterns MaxInt and MinInt returns the largest (respectively smallest) integer on the machine.

 ```(# i,j,k: @integer do 3 -> i; '? '->puttext; getint->j; (* read an integer from keyboard *) ((i,j) -> Max, j+5) -> Min -> k; 'k is '-> puttext; k -> putint; newline; (if k-1 // 5 then ... // 17 then ... if) #)```

### 1.3.4 The Boolean Pattern

#### 1.3.4.1 Logical operators

In the current implementation, true and false return respectively the values 1 and 0. The unary operator not and the binary operators and, xor, and or can be applied to booleans.

Booleans are used in the traditional way:

 ```(# aBoolean, anotherBoolean: @boolean; a: @integer do ... (if aBoolean then ... else (a>7) and (a<17) -> anotherBoolean if) #)```

### 1.3.5 The Real Pattern

#### 1.3.5.1 Arithmetical operations

The arithmetical operations: +, -, *, div (or /), and the relational operations: =, <>, >, >=, < and <= are defined for reals. The patterns MaxReal and MinReal (defined in math.bet) returns the largest (respectively smallest) real on the machine.

The following example shows how to use reals. The pattern putreal is described later.

 ```(# x,y: @real; do ... -> x; 'Print the number 1.23:' -> putline; y -> putreal; newline; x -> y; (if x=y then 'x and y are equal!' -> putline if); '3.0*7.0 = ' -> puttext; 3.0 * 7.0 -> putreal; newline; '(-4.0)*(-3.0) = ' -> puttext; -4.0 * (-3.0) -> putreal; newline; '(-4.0)/8.0 = ' -> puttext; -4.0 div 8.0 -> putreal; newline; #)```

### 1.3.6 The Char Pattern

#### 1.3.6.1 ASCII

The char pattern enables the manipulation of characters. Characters can be expressed as literals or as the corresponding ASCII values. The pattern Ascii defines all non-printable characters as constants (such as null, nl, cr, esc, del). Newline however, is a variable containing either nl or cr depending on the computer.

Ascii also contains local patterns for various conversions and testings of characters. E.g. the patterns IsDigit, IsLetter, IsUpper and IsLower are provided for determining the kind of a character. IsSpace testes whether the character is sp, cr, nl, np, ht or vt. Conversion is available through the upCase and lowCase patterns.

The following example shows how to use char and upCase:

 ```(# a,b: @char do 'a' -> a; 98 -> b; (if a -> Ascii.upCase // 'A' then ... // 'B' then ... ... if) #)```

### 1.3.7 The Repetition Pattern

The BETA compiler also implements repetitions. Betaenv contains the repetition pattern, defining the available operations on repetitions (apart from the lookup operation: []). These operations are range, new and extend. Range returns the number of repetition positions, new makes it possible to allocate an entire new repetition, and extend is used for dynamically extension of the repetition. Note that the repetition pattern cannot be used as a superpattern:. Also note, that it is only allowed to make repetitions of integer, boolean, char, real, and object references.

 Basic Libraries - Reference Manual © 1990-2002 Mjølner Informatics [Modified: Friday January 4th 2002 at 13:10]