Fackward

From Esolang
Jump to: navigation, search

Fackward is a stack-based esoteric programming language created by User:Koen in 2012. It is an attempt to make a stack-based, but still Turing-Complete, language similar to Fueue, which is queue-based. In Fackward, there is only one data structure. It is made of two stacks, the forward stack and the backward stack. When execution starts, the source of the program is converted to the forward stack. The backward stack is initially empty.

Evaluation proceeds in a way very similar to Fueue:

  • Look at the top element of the forward stack.
  • If it is a numeric value, it is popped, converted to a character and printed.
  • If it is a function, and there are enough values of the appropriate type directly behind it in the forward stack, the function and those values are popped, and the result is pushed on top of the backward stack.
  • Otherwise, it is simply popped and pushed back on top of the backward stack.
  • If the forward stack is empty, switch the forward and the backward stacks.
  • If the two stacks are switched this way twice in a row, without any characters being printed or functions being executed between the two switches, a character is taken from input and its unicode value is pushed on top of the (empty) backward stack.

In practice, Fackward works exactly like Fueue, except the "queue" is read forward and backward.

The only things allowed in a program are nonnegative integers (in base 10), the functions described below, square brackets encoded subprogram blocks, and whitespace.

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...

Examples

Cat program/Null program


As in Fueue, the null program is a cat, although it doesn't handle end of file.

Hello, world!

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

Infinite Loop

::

See also

  • Fueue, which Fackward is merely an ersatz of
  • Ftack, a joke language similar to Fackward