4 Repetition Constructors

4.1 Value Repetitions

Consider a value repetition:

R: [exp] @T
where T is a basic pattern.

A repetition object may be constructed and assigned to R in the following way:

(E1,E2,...,En) -> R

where E1, E2, ... En are evaluations of type T.

A repetition object with range = n is constructed and R[i] = Ei, i in [1,n].

A repetition object consisting of one element may be constructed using:

E -> R

4.2 Example

The following is an example of using repetitions constructors:
(# a,b: @integer;
   R:[1] @integer
do 10->a; 20 -> b
   (a,b,a+b) -> R;
   (for i: R.range repeat R[i] -> putint; ' '-> put for)
The above example will print the sequence
10 20 30

4.3 Variable number of enter parameters

Repetitions may be used to define patterns with a limited form of a variable number of parameters. Consider the following example:
   (# S: ^stream;
      V: [1] @integer;
      sep: @char
   do (for i: V.range repeat
           V[i] -> S.putint; sep -> S.put
Pattern foo may be used in the following way:
(screen[],(1,2,3,4,5),'-') -> foo
which will print the following sequence to the screen:

BETA Language Modifications - Reference Manual
© 1999-2002 Mjølner Informatics
[Modified: Thursday December 5th 2002 at 11:20]