Fungify

Fungify is a utility for formatting numbers for the Funge family of programming languages. It emits Funge code for pushing a given integer on the stack.

Fungify is written in Haskell.

Download

The source code is available here:

FileTypeSize (octets)Last modified
Fungify source codeHaskell source file15 4332014-12-29

Motivation

Pushing numbers on the stack in Funge is not as trivial as in most programming languages. The only available numeric constants are 0–9 in Befunge-93 or 0–15 in Funge-98. Strings can also be used to extend those ranges to e.g. 0–127 for ASCII, although the availability of some values depends on your willingness to put non-printable characters in your source code.

Thus, to e.g. put 182 on the stack in Befunge-93, one might use the sequence 954**2+, corresponding to the arithmetic expression 4 * 5 * 9 + 2, which is indeed equal to 182. Figuring this out can be a labourious or distracting process, which Fungify automates. In this case, the output of fungify dec 182 is 2794+**, corresponding to (4 + 9) * 7 * 2, which also equals 182. (The dec constrains Fungify to use the numbers 0–9: see usage, below, for details.)

Usage

Other than integers, Fungify takes three classes of command line arguments:

For example:

$ fungify each dec +hex +latin1 dc 123456
3 8 8 3 2 5 8 d * * * + * * *
6 4 8 3 10 8 d * * + * * *
192 3 10 64 * + *

$ fungify dec +hex +latin1 dc 123456
192 3 10 64 * + *

Typically, latin1 results in the shortest code sequence, but due to the heuristics used and the lack of optimization, with large numbers it may be beneficial to specify other sets as well. For example, in this case ascii ended up being one character shorter:

$ fungify each ascii +latin1 999999999999999
'o9')738*+f4'@*+"1! +@"***+*****
'o9')738*+'ï' +'1'`b'+'@***+*****