Esolangs are cool. I especially like Befunge. I like Befunge so much, in fact, that I'd like to write complex utilities and apps in it.
What? It can't be done? That's what they told me too. But I'll show them; I'll show them all!
This Gist is a proof of concept to demonstrate how to run Python commands from a Befunge programme -- opening up a world of opportunity.
- Clone and compile https://github.com/CzechsMix/FungePP
- Navigate to where the freshly built executable is.
- Put the
wrap.py
andpython_executor.bef
in that directory. - Run
python2 wrap.py python_executor.bef 0
The expected output is the Ascii values from 1 to Z.
The specified Befunge programme reads a character in from stdin (in this case it will be 0) and outputs a python instruction to stdout that will look something like this: o=chr(ord('0')+1);p()
. Python will read that line and execute it. If the variable o
is set, it's value is written back to stdin to be read by befunge next time it gets input.
Befunge can, thus, pipe instructions to its Python environment and results get piped back. What could go wrong?
One can obviously abuse this and offload the main logic of the programme into Python but the real beauty comes in when calls to Python are used purely to do things that Befunge can't e.g. read from the disk, make network requests, etc.