Flobnar
Befunge turned functional. Nothing moves; every cell is an expression that asks its neighbours for values.
Chris Pressey, 2011 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Chris Pressey designed Flobnar in 2011 as a functional counterpart to Befunge, for Befunge's 18th birthday. The grid looks like Befunge, but there is no instruction pointer and no stack. The program is the value of the cell west of @. An arrow is worth whatever the cell it points at is worth, + is worth its north neighbour plus its south neighbour, and so on. Loops are recursion, a path of arrows that leads back to where it started.
The machine
Numbers are unbounded integers. A cell knows which way it was asked from, so "forward" means further in that direction. Evaluation wraps round the box around the non-space cells. This implementation follows Reconcyl's Rust interpreter, which is what TIO runs.
| Term | Is worth |
|---|---|
0-9 | Itself |
< > ^ v | The cell it points to |
space, # | The next cell forward; the one after that |
+ - * / % | North op south; / and % by 0 pass forward |
` | 1 if north is greater than south | |
! | 1 if forward is 0 |
_ \| | West or east, north or south, as forward is not 0 or is |
\ | Forward, with south bound as the argument |
: | The argument |
g p | The code at north, south; put forward there |
, ~ | Print forward as a byte; read a byte |
? | A neighbour chosen at random |
TIO runs it with -r, so the program's own value is not printed; only , prints.
Example
In the second program , asks west for +, which asks north for 2 and south for the arrows.
In the second program , asks west for +, which asks north for 2 and south for the arrows. They lead to *, worth 9 times 7. So , prints 65.
Patterns it teaches
- Two-dimensional control flow: arrows lay out an expression tree on the grid.
- Self-modifying code:
prewrites cells, which is how a program keeps state.
Further
See also
Functional paradigm
Self-modifying
Write your own in Run Convert a program from Flobnar
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: flobnar.
Command line
shib run flobnar -e '~,@' --input 'xyz'shib manual flobnarSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/flobnar.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org