This is the in-browser interpreter of the Flurry programming language, using the I/O formats of Reconcyl/flurry (which is considered the reference implementation).
Flurry is a language where the only meaningful tokens are balanced brackets () {} [] <>
.
<>
evaluates to S combinator.()
evaluates to K combinator.{}
pops an item from the stack and evaluates to that. If the stack is empty, I is popped.[]
evaluates to the Church numeral representing the stack height.
<a b ... c>
evaluates toa . b . ... . c
(function composition of all terms inside the brackets).[a b ... c]
evaluates toa b ... c
(function application).(a b ... c)
is the same as[...]
except that it also pushes the evaluated value to the stack.{a b ... c}
is a lambda expression where{a b ... c} x
pushesx
and evaluates to[a b ... c]
.
When the program starts, the input values are pushed to the stack as Church numerals. The entire program is then strictly evaluated like a lambda calculus expression (in applicative order). When the program is in normal form (no longer reducible), the stack contents and the program's value (both optional) are interpreted as Church numerals and outputted as their integer values.
If you have some experience with the Haskell (reference) interpreter, you will find the interface familiar.
- Code: Enter the Flurry source code. Non-Flurry characters are ignored.
- Stdin: Enter input values as whitespace-separated integers (integer mode) or any string (character mode).
- Extra args: Enter whitespace-separated integers to push on top of values from stdin. You can use it for e.g. a task which requires taking a string and an integer input.
- IO flags: Set the I/O modes. Must match
/^[ibvn][ivn][ibn]$/
. Explanation in order:- 1st char: Stack output
i
: Integer outputb
: Binary (text) outputv
: Verbose outputn
: No output (ignore stack contents)
- 2nd char: Return value output
i
: Integer outputv
: Verbose outputn
: No output (ignore return value)
- 3rd char: Stdin input
i
: Integer inputb
: Binary (text) inputn
: No input (ignore stdin)
- 1st char: Stack output
- Reduction limit: The interpreter counts the number of reduction steps. When it hits the limit, evaluation is aborted and error is printed.
Also, the page has the permalink feature (click the #
symbol at the top).
A permalink contains information about all active fields, so anyone clicking the permalink can
try running the code right away. It also generates a Code Golf.SE post under Output.
This interpreter uses number and Succ
nodes internally to shortcut common arithmetic operations.
(This feature may be a source of bugs; if you find a bug, please let me know by opening an issue here
or pinging Bubbler at the Flurry chat room on SE.)
Reduction rules are outlined in the big comment at the top of flurry.ts
.
The interpreter evaluates the program one step at a time, and runs to completion by repeating the single-stepping function. As a result, it is possible to count the number of steps taken and abort if it takes too much time to complete. This feature is necessary to not hang the browser.
It might also help in visualizing the single steps, but it is not yet implemented.
The v
output mode was added for both stack and return value outputs. This shows the terms as
a pretty-printed internal representation. This will help debugging both the Flurry code and
the interpreter. I decided to add it because I found it hard to build complicated intermediate
values without any way to inspect them.
MIT