# CPL (programming language)

Paradigm Multiparadigm procedural, functional, structural, imperative University of Cambridge, University of London 1960-е Static None ALGOL 60 BCPL, POP-2, B, C

Combined Programming Language (CPL) is multi-paradigm programming language that was developed jointly between the Mathematical Laboratory at the University of Cambridge and the University of London Computer Unit during the 1960s. The collaborative effort was responsible for the "Combined" in the name of the language (previously, the name was Cambridge Programming Language). The predecessor of the language BCPL, which, in turn, is a precursor of the C language.

## History

Combined Programming Language (CPL)[1] was developed jointly between the Mathematical Laboratory at the University of Cambridge and the University of London Computer Unit during the 1960s hence CPL gained the nickname "Cambridge Plus London". In 1963 it was concurrently being implemented on the Titan Computer at Cambridge and the Atlas Computer at London.

It was heavily influenced by ALGOL 60, but CPL was intended for a wider application area than scientific calculations and was therefore much more complex and not as elegant as ALGOL 60. CPL was a big language for its time. CPL attempted to go beyond ALGOL to include industrial process control, business data processing and possibly some early command line games. CPL was intended to allow low-level programming and high level abstractions using the same language.

However, CPL was only implemented very slowly. The first CPL compiler was probably written about 1970, but the language never gained much popularity and seems to have disappeared without trace sometime in the 1970s.

### CPL Descendants

BCPL (for "Basic CPL", although originally "Bootstrap CPL"), was a much simpler language based on CPL intended primarily as a systems programming language, particularly for writing compilers; it was first implemented in 1967, prior to CPL's first implementation. BCPL then led, via B, to the popular and influential C programming language.

## Language description

### Program structure

A CPL program is made up of definitions and commands. The definitions may be regarded as instructions to associate certain names with data items, data structures, functions, or process descriptions. The commands may be regarded as instructions to perform some evaluation and/or some rearrangement of the information held in the computer. Programs are divided into subsections called blocks; in the simplest case a block consists of a series of definitions which are activated simultaneously, followed by a series of commands which are executed in sequence (unless a command specifies a change of sequence). Blocks may be nested within other blocks. CPL blocks are similar to ALGOL blocks.

### Data types

 real Real number. Precision and range permitted are implementation-dependent. integer Integer number. Permitted range is implementation-dependent. complex Complex number. Implemented as an ordered pair of real items. Boolean Logic variable (truth-item)). logical Bit array, length is implementation-dependent. long logical Bit array which has more or equal length than logical. Length is implementation-dependent. string Sequence of symbols from the CPL alphabet. label Command label. general Designates an item whose type is not fixed and may, therefore, vary at run time. file File description data structure. Needs to be used for file I/O. array Array. Example: real 2 array A, where 2 is number of dimensions. Number of elements are set by calling special Array function. list List of elements like LISP. Example: list L = a, b, c

### Constants

• Numberic constants are set in decimal notation: 59, +8.76, -0.35.
• Logical constants are bit patterns expressed in binary or octal form as indicated by a preceding 2 or 8. The pattern is assumed to be right justified; however, it may be shown to be justified from the left or right by the presence of a bar on the left or right of the constant. Example: 8 777, 8|55, 2 1110000 |.
• String constant is represented by a sequence of symbols enclosed in string quotes: ' and '.
• Boolean constants are the basic symbols true and false.

### Expressions

There are two possible modes of evaluation of an expression in CPL, known as the left-hand (LH) and right-hand (RH) modes. All expressions can be evaluated in RH mode, but only certain kinds of expression are meaningful in LH mode. When evaluated in RH mode an expression is regarded as being a rule for the computation of a value (the RH value). When evaluated in LH mode an expression effectively gives an address (the LH value).

Unlike the later languages, fused write two names of variables is interpreted as their multiplication (eg, bc is multiplying b by c).

### Operators

• + - x /
• Unary + и -
• ↑ (power)
•  := (assignment)
• ~ (NOT)
• /\ (AND)
• \/ (OR)
• imp (implication)
• < ≤ = ≠ > ≥
• → (like C ternary operator)
• where (like let in LISP, eg.: p : = ax ↑ 2 + bx + c/x where x = 2a ↑ 2 + b)
• result of (used to return result from functions which consist of more than one operator)

### Conditional operator

There are three forms of conditional operator:

• if ... then do ...
• unless ... then do ...
• test ... then do ... or do ...

### Cycle operator

There are following types of cycle operators:

• while ... do ...
• until ... do ...
• ... repeat while ...
• ... repeat until ...
• for v = 1, 3, 6, 10 do ...
• for v = step 1, 2, 10 (like for (v = 1; v < 10; v += 2) in C)

This form may be concatenated like this: for v = step 0, 1, 10 then step 40, 2, 60

### Functions

Functions are defined by the following syntax::

function F [x, y] = ax ↑ 2 + 2bxy + cy ↑ 2

If function is recursive, it should be marked by rec keyword.

If functions consist of more than one expression, it should use result of command to return a value.

### Input/Output

A program is regarded as processing data arriving in one or more input streams, and producing results in one or more output streams. One must use Input function to open stream for reading and there are following functions to read data:

• Readsymbol, Nextsymbol and Lastsymbol which allow user to work with stream like with the paper label

One can use this functions to output data:

• Write to output variable value
• Write2 and Write8 to output bit array value
• Writesymbol to work with stream like with paper tape
• Layout to arrange output block size

## Language features

• Multiple initialiation real a, b = 5, 6. real a, b = 5 (value 5 will be assigned to both variables).
• Multiple assignment: a, b := b, a.
• Unusual for modern languages way to combine functional and imperative features
• A large variety of looping cycle operators
• A large number of operators that are missing in today's keyboard layout

## Code samples

### Recursive factorial

rec function Fact[x] = (x = 0) -> 1, xFact[x — 1]

### Iterative factorial

function Fact2[x] = result of
§real f = 1
until x = 0 do
f; x := xf, x - 1
result :=f §

### Euler function calculation

function Euler [function Fct, real Eps; integer Tim]= result of
§1 dec §1.1 real Mn, Ds, Sum
integer i, t
index n=0
m = Array [real, (0, 15)] §1.1
i, t, m[0] := 0, 0, Fct[0]
Sum := m[0]/2
§1.2 i := i + 1
Mn := Fct[i]
for k = step 0, 1, n do
m[k], Mn := Mn, (Mn + m[k])/2
test Mod[Mn] < Mod[m[n]] /\ n < 15
then do Ds, n, m[n+l] := Mn/2, n+1, Mn
or do Ds := Mn
Sum := Sum + Dt
t := (Mod[Ds] < Eps) -> t + 1, 0 §1.1
repeat while t < Tim
result := Sum §1.

### Finding maximum element of array

Max(Items, ValueFunction) = value of
§ (Best, BestVal) = (NIL, -∞)
while Items do §
result is Best §⃒