# KRC (Kent Recursive Calculator)

This page was last modified on 21 May 2016, at 21:41.

Paradigm | functional |
---|---|

Designed by | David Turner |

First appeared | 1981 |

Website |
{{ |

Influenced by | |

LISP, SASL | |

Influenced | |

Miranda |

**Kent Recursive Calculator**(**KRC**) - lazy (call-by-need) functional programming language based on higher order recursion equations.

## Contents

## History

KRC was developed in 1981 by David Turner based on another functional language named SASL he developed. In 1985 david Turner create another functional language named Miranda based on KRC.

KRC was create for learning. Turner in his book "Functional Programming and Its Applications" explains why he does not use LISP:

Semantics of LISP are rather complicated and include a number of features which would in no sense be regarded as functional.

## Using

During the period from 1982 to the time of creating Miranda language in 1985, KPC was used for functional programming learning in University of Kent at Canterbury in UK.

## Feautures

Program (Turner called it script) is a set of equations, giving mathematical defenitions of various entities. KRC functions notation is much more like mathematical than notations in other functional languages.

KRC works with 4 types

- number,
- string,
- list (including an infinite),
- function.

## Functionality

- Lazy evaluation - strategy which delays the evaluation untill its result is needed.
- Guard expressions - boolean conditional to check a variants of calculations.
- Pattern metching - comparison with exact value or string or predicate or data type or any supported languages construction.
- ZF-expresiion (list comprehensions) - a compact description lists operations, including infinite lists.
- Interactivity: built-in commands for editing scripts, save them and loading from file.
- A set of library functions for working with lists (map, filter, invert, rotate, swap etc.)

## Syntax

### Lists

Elements write in square brackets. List can be created by several ways:

- enumeration

[1,2]

- concatenation

0: [1,2]

- as interval from a to b

[a..b]

- as infinite list

[1..]

### Functions

Function name writes on the left from parameters.

Example: squaring functionsq n = n*n

## Примеры

### Calculating variable`s value

```
r = u/v
u = x+1
v = 11
x = 23
```

Order of equations doesn`t matter cause KRC is lazy language and the result of any equation wouldn`t be calculated until not needed.

Command to get value of r:

`r?`

### Prime numbers calculating

```
primes = sieve [2..]
sieve (p:x) = p:sieve {n; n <- x; n%p > 0}
```

Request to output numbers:

`primes?`

Prime numbers will be printed indefinitely (or rather until it runs out of space)

`[2, 3, 5, 7, 11, 13, 17`

## Versions

- Writed by Turner on BCPL language - structured language developed in Universyty of Cambridge in 1966 and influenced the B and C languages. This version is designed for EMAS.
- Writed by Simon J. Croft's later on C under Unix.

## Присоединяйся к команде

ISSN:

## Следуй за Полисом

Оставайся в курсе последних событий

## License

Except as otherwise noted, the content of this page is licensed under the Creative Commons Creative Commons «Attribution-NonCommercial-NoDerivatives» 4.0 License, and code samples are licensed under the Apache 2.0 License. See Terms of Use for details.