Ixth

From Esolang
Jump to navigation Jump to search
Ixth
Designed by User:munvoseli
Appeared in 2022
Computational class Turring complete
Reference implementation ixth on github
File extension(s) .ixth, .txt

Ixth is a stack-based language. Instead of operators such as drop, swap, or dup, it features one customizable stack operator.

( a b -- b a ) is equivalent to swap.

( a -- ) is equivalent to drop.

( a -- a a ) is equivalent to dup.

( a b c -- c a b ) and ( a b c -- b c a ) perform rotations.

Commands

Commands
Form Example Effect
( a b c ... -- a b c ... ) ( a b -- b a ) for each left element, pop from the stack and assign to a corresponding temporary variable, then rearrange the values according to the right pattern and append to the stack
print pop the top element and print
add pop the top two elements, add together, and push result
sub pop the top two elements, subtract (second of stack - top of stack), and push result
if ... [else ...] fi if 1 print else 2 print fi pop the top element, if nonzero, execute the if block, if zero and there's an else block, execute that
{ ... } enclose block
gof go forward, skips forward to the nearest } (end of block)
gob go backward, skips backward to the nearest { (start of block)
func ... ret declare a function, only one return at the end allowed (according to the implementation)
digits 123, 8, 723 push the first digit of the number onto the stack
name my_func, double call the function with the given name

Computational class

Arbitrary loops can be created using blocks and the gob command. The if construction can be used in conjunction with the command for conditional looping. There are no explicit bounds for the stack's size, nor for the size of the elements. As such, counter machines, particularly structured variants, can be translated into Ixth.

Example

9 8 add print

5 6 ( a b -- b a ) print print

func hello
5 5 add print
ret
hello

8
{
 ( a -- a a ) print
 1 sub
 ( a -- a a ) print
 ( a -- a a ) if
  1 gob
 fi
 1 gof
}
( a -- )

8 8 8 add add print

0 if
 1 print
else 1 if
 2 print
 0 if
  1 print
 else 1 if
  4 print
 fi
else 1 if
 3 print
fi