CPL

Implementation of programming language CPL

A dialect of CPL described in the article “The Main Features of CPL” (1963). It exists solely as a theoretical description, since it differs from dialects implemented in London CPL and Cambridge CPL.

Examples:

Hello, World!:

Example for versions CPL

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

Write("Hello, World!")

Factorial:

Example for versions CPL

(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:

Example for versions CPL

(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 §