Huit

From Esolang
Jump to navigation Jump to search

Huit means 'eight' in French. The joke is that 'eight' can refer to the eight ball, and cue sounds like 'queue'. Huit is a one-dimensional queue-based Turing-complete esoteric programming language created by User:TheCanon2.

Commands

Huit has a single queue. The data in the queue can only be a float or a string. Huit has fifteen commands.

Arithmetic operators

Command Action
+ Dequeue the first two items, enqueue the sum.
- Dequeue the first two items, enqueue the difference between the first item dequeued and the second item dequeued.
* Dequeue the first two items, enqueue the product.
/ Dequeue the first two items, enqueue the quotient of the first item dequeued and the second item dequeued.
% Dequeue the first two items, enqueue the modulo of the first item dequeued and the second item dequeued.

The plus and modulo are the Python plus and modulo, meaning they can be applied to strings.

Computational operations

Command Action
&x Enqueue a float with the value x.
&"s" Enqueue a string with the value s.
: Duplicate the first item of the queue.
? Dequeue.
(s) Define a jump location with label s.
[c] Dequeue the first item, then follow switch case c.

The switch case can take any amount of parameters. For example, statement [a,b,c,d] means goto a if the value dequeued was 0 or empty, goto b if the value dequeued was 1, goto c if the value dequeued was 2, goto d if the value is anything else. The last statement is always the 'anything else' statement.

Commas, brackets, and square brackets should never be used in the name of a jump location.

I/O functions

Command Action
> Dequeue and print the first item.
>' >, but convert into an ASCII character if a float.
< Enqueue a character from the input.
<' Prompt the user for a float and enqueue the entire input.

Examples

Hello, World!

&"Hello, World!">

Truth machine

<':[0,1](1)::>[1](0)>

Cat

(cat)<>[cat]

If there is nothing to dequeue, nothing will be dequeued.

99 bottles of beer

&100(Loop)&1&"%d bottles of beer on the wall.":&1&"%d bottles of beer.":&1
&"Take one down, pass it around,\n%d bottles of beer on the wall.":&2
-:?-:?-:?-:?%%%:?>>>:[End,End,Loop](End)

Uses Python modulos to replace %d with the appropriate number. Newlines have no meaning in Huit.

XKCD Random Number

&4>

Print all of Unicode

&0&0>'(A)&1+::>'[A]

Computational class

Cyclic tag system

Huit is Turing-complete for cyclic tag system can be trivially compiled into it.

&0 Write 0 to the data-string.

&1 Write 1 to the data-string.

? Delete the leftmost bit.

&A[Loop] Repeat the loop.

However, this process always loops.

Minsky machine

A more concrete proof of Turing-completeness would be to compile a section 14.2 Minsky machine with two sub-registers into Huit.

&2* Increment sub-register 2

&3* Increment sub-register 3

&2:%:?[div,pass](div)&2/:[jump](pass) Conditionally decrement sub-register 2

&3:%:?[div,pass](div)&3/:[jump](pass) Conditionally decrement sub-register 3

Implementations

The Python script in this article is an incomplete interpreter.