REPL#

The REPL is a very helpful tool for functional programming languages like bruijn. You can use it to continuously test or execute parts of your code.

You can start the REPL using stack run or (if installed) bruijn.

Any valid term will get reduced to normal form after pressing enter. Common data structures will get resolved in a seperate line if detected (e.g. numbers, lists or strings).

Definitions#

Since everything you type will get evaluated, definitions (compared to definitions in files) require an equal sign:

> id = [0]
> id
[0]

Commands#

:import/:input#

Equivalent to the respective commands in files.

> :import std/Math .

:test#

Equivalent to the test command in files.

> :test ([0]) ([[1]])
ERROR test failed: [0] = [[1]]
      reduced to [0] = [[1]]

:watch#

:watch re-imports the file automatically after every saved change. It will rerun any test the watched file contains.

> :watch collatz-proof

This can be very helpful for test driven development.

:time#

Measures the time from start of reduction to its end (normal form) in seconds.

> :time fac (+30)
0.15 seconds

:blc#

Translates both the unreduced and the reduced expression to binary lambda calculus. Helpful for golfed compilation.

> :blc [0] [0]
0100100010
0010

:length#

Measures the length of the binary lambda calculus encoding of both the unreduced and the reduced expression. Helpful for golfed compilation.

> :length [0] [0]
10
4

:free#

The free command frees the current environment including all defined identifiers and imported files.

> id = [0]
> :free
> id
ERROR undefined identifier id