Ftack

From Esolang
Jump to: navigation, search

Ftack is a stack-based esoteric programming language created by User:Koen in 2012. Everything works exactly like in Fueue, except with a stack instead of a queue.

Everything is stored in a single stack. The source of the program is converted to this stack on execution.

Evaluation proceeds as in Fueue:

  • Look at the top element on the stack.
  • If it is a numeric value, convert it to a character and print.
  • If it is a function, and there are enough values of the appropriate type directly under it on the stack, the function and those values are popped, and the result is pushed back on top of the stack.
  • Otherwise, it is simply pushed back on top of the stack.
  • If the stack reaches this last stage, a character is taken from input and its Unicode value is pushed to the top of the stack.

The only things allowed in a program are nonnegative integers (in base 10), the functions described below, square bracket encoded subprogram blocks (which are actually stacks), and whitespace. However, to be faithful to the Last In, First Out principle of a stack, it is expected that the program be written in reverse order.

Functions

Function Effect Before After
+ Adds two numbers +ab... (a+b)...
- Negates a number -a... (-a)...
* Multiplies two numbers *ab... (a*b)...
/ Integer divides two numbers /ab... (a/b)...
% Logically inverts a number (0 to one, n to 0) %a... (!a)...
: Duplicates a value :a... aa...
~ Swaps two values ~ab... ba...
! Pops a value !a... ...
$ Pushes a number of copies $ab... (a lots of b)...
( Turns a value into a block (a... [a]...
< Adds another value into a block <[foo]b... [foob]...
) Deblocks a block )[foo]... foo...
H Halts immediately H...

Because of the nature of Ftack, the result of all arithmetic functions (+, -, *, /, %) is immediately popped and printed.

The computational class is unknown, but it is very likely that most problems cannot be solved in Ftact.

Examples

Cat program/Null program


In Ftack, like in Fueue, the null program is a cat. In Ftack, though, any program starting with a block, or with a function not followed by enough values of the appropriate type, is also a cat. In fact, most programs end up on a cat.

Infinite loop

::

This loop doesn't do anything, but it doesn't end up being a cat, which in Ftack can be considered a victory.

Hello, World!

H 10 33 100 108 114 111 119 32 44 111 108 108 101 72

Computational class

Ftack was intended as a joke and is expected to have a relatively low computational class. Ørjan suggested that every program would eventually either halt, become a cat, or end up with :: on top of the stack; and that this would happen in a number of steps less than max(m-1, 1) * n_$ + 2 * n_: + n_rest, where m is the largest number appearing in the initial program, and n_$, n_: and n_rest the number of $, of : and of other values, respectively.

A more serious variant of Fueue could be to have the result of functions be pushed on top of the stack (like in Ftack), but non-executed functions be enqueued at the back (like in Fueue). The computational class of that variant is yet unknown.