Operators with multiples
Keywords: pame

Subsections

- Exercises

#
Operators with multiples

No operators are defined in the standard prelude for multiples whose elements have modes `INT` or `REAL`. This is not a drawback as you will learn in chapter 6. Nor are there any monadic operators in the standard prelude for multiples of `CHAR`. However, multiples of `CHAR` occur so often, that two dyadic operators are available for them.

The operator `+` is defined for all combinations of `CHAR` and `[]CHAR`. Thus, the formula

       "abc" + "d"

yields the value denoted by `"abcd"`. With these operands, `+` acts as a concatenation operator. The operator has a priority of 6 as before.

Multiplication of values of mode `CHAR` or `[]CHAR` is defined using the operator `*`. The other operand has mode `INT` and the yield has mode `[]CHAR`. For example, in the declaration

       []CHAR repetitions = "ab" * 3

`repetitions` identifies `"ababab"`. The formula could have been written with the integer as the left operand. In both cases, the operator only makes sense with a positive integer.

## Exercises

3.10
  Given the identity declarations

         []CHAR s = "Dog bites man",
                t = "aeiou"

  what is the value of the following formulæ? Ans
  (a)
    `"M"+s[UPB s-1:]+s[4:10]+"d"+s[2:3]`

  (b)
    `s[5]*3+2*s[6]`