CPL

Version of implementation CPL of programming language CPL

The only existing version of the theoretical description of CPL, 1963.

Examples:

Hello, World! - CPL (444):

Generally Write outputs a list of elements, but in this case it prints a string literal.

Write("Hello, World!")

Factorial - CPL (445):

(Example from language description) This is a recursive factorial definition (note the rec modifier which stresses this). To implement different processing scenarios for different values of x, a conditional expression is used instead of if.

rec function Fact1[x] = (x = 0)  1, xFact1[x  1]

Factorial - CPL (446):

(Example from language description) This code shows an iterative way to calculate factorial.

result of clause allows to use a block as an expression. The body of the block must contain an assignment to variable result. The block may contain local variables, but nothing which could result in a side effect (for example, changing the values of external variables is prohibited). This clause is typically used with function definitions.

Loop body uses simultaneous assignment of new values to the variables. Both of them use small names, so the language allows to skip multiplication sign between them — xf is treated same as x*f.

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