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.
The source code is available here:
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.)
Other than integers, Fungify takes three classes of command line arguments:
Output format selection arguments:
- Funge code — specifically Unefunge, since it is always one-dimensional
- Reverse Polish notation
- dc code
The last argument given overrides any previous ones. Alternatively, if a
+ is prefixed to an argument, that output format will be used in addition to the previous selection.
Available number set selection arguments:
- Decimal digits: 0–9
- Hexadecimal digits: 0–15
- ASCII: 0–127, excluding non-printable characters
- ISO/IEC 8859-1: 0–255, excluding non-printable characters
These may also be prefixed with
+ to select multiple number sets.
each. These only have an effect when multiple number sets have been selected.
best is the default, and means to output the shortest code sequence obtainable using any of the selected sets. With
each, a separate code sequence for each selected number set is printed.
$ 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 * + *
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