Hanoifuck

From Esolang
Jump to navigation Jump to search
Hanoifuck
Paradigm(s) stack-driven
Designed by Joshua Barretto
Appeared in 2019
Memory system stack-based
Computational class Turing complete
Reference implementation Hanoifuck C Interpreter
Influenced by Brainfuck
File extension(s) .hf

Hanoifuck is an esoteric programming language invented by Joshua Barretto. It draws influence from Brainfuck, but swaps Brainfuck's tape-driven memory model for a multi-stack LIFO memory model similar in conception to the 'Towers of Hanoi' puzzle game.

Language overview

Syntactically, and in terms of code execution, Hanoifuck behaves exactly like Brainfuck. However, it differs in the instructions it has and the way in which they operate upon the memory model.

Hanoifuck's memory model is composed of 3 independent LIFO stacks of bytes. Each stack can have bytes push onto them or popped off them (through various operations). At any one moment, only one of the stacks is operated upon. The ! instruction is used to switch between each of the stacks in turn.

Instruction Description
+ Addition: Pop the two most recent values off the current stack as a and b. Then, push a + b
- Subtraction: Pop the two most recent values off the current stack as a and b. Then, push a - b
$ One: Push the value 1 onto the stack
! Swap: Switch to the next of the three stacks, looping if necessary
, Read: Read a single character from stdin, replace the item at the top of the current stack (similar to Brainfuck)
. Write: Write the ASCII value of the item at the top of the current stack to stdout (similar to Brainfuck)
[ Skip forward: As in Brainfuck, skip forward to the next matching ] if the item at the top of the current stack is zero
] Skip backward: As in Brainfuck, skip backward to the next matching [ if the item at the top of the current stack is non-zero

Comparisons with Brainfuck

While the execution semantics of Hanoifuck is deliberately very similar to Brainfuck, the use of stacks makes static analysis, and hence optimisation, of Hanoifuck much more viable than that of Brainfuck.

Examples

A simple example that outputs HELLO to the console:

$+$+$+[$-!$+$+$+$+!!]![$-!!$+$+$+$+$+$+!]!!.$-$-$-.$$$$$$$+++++++..$$$+++.[$-]$+$+[$-!$+$+$+$+$+!!]!.

External resources