Revaver2pi

From Esolang
Jump to: navigation, search

This is a variant on Revaver created by User:Zzo38 in 2006.

There are an infinite numbers of stacks with integers on it, numbered by integers, one main stack, and one accumulator also which can store an integer.

Input is the data initial in all stacks and in accumulator, output is final data of all stacks and accumulator.

No stack is allowed to contain any number which is immediately followed by the same number.

Any empty stack the top value is considered to be zero, so you can't push zero to an empty stack, and popping an empty stack has no effect.

I believe programs without ! form a group.

Expressions

  • 'a=b Returns -1 if a less than b, 0 if a equal to b, 1 if a greater than b
  • 'a_b Subtract numbers
  • 'a.b NAND numbers
  • 'a' Absolute value of a
  • # Use value of accumulator
  • 'a$b Mingle a,b
  • 'a( Left-half unmingle of a
  • 'a) Right-half unmingle of a

Commands

Note that each command is the reverse of itself.

  • SWAM = Swap accumulator with top of main stack, unless empty stack or it would cause consecutive duplicates
  • SWMS n = Swap main stack with number n stack
  • PP n = Push n to main stack, or pop if pushing would cause consecutive duplicates. (No effect if trying to push zero to empty stack)
  • TEL n m = Search forward in program (wrap around) continue execution at first found TEL that n evaluates to same value. m is a optional group number. Even though only n is considered for where to jump, a TEL command with a abstained group will do nothing, and a TEL command that is working will skip other TEL commands with abstained groups.
  • XOR n = XOR value at top of main stack with n unless empty or causing consecutive duplicates
  • IODE = Increment accumulator if odd, decrement if even
  • IEDO = Decrement accumulator if odd, increment if even
  • NEG = Value of accumulator multiply by negative one
  • SUB n = Set top of main stack to n minus top of main stack, unless empty or causing consecutive duplicates
  • CMS = Set accumulator to number of entries on main stack minus value of accumulator
  • TTG n = Toggle teleport group number n
  • SUBS = Set accumulator to top of main stack (zero if empty) minus accumulator

There are a few extra commands that are not completely reversible because they do input/output:

  •  !WT t = Write text and newline.
  •  !WW t = Write text and space.
  •  !WN n = Write number.
  •  !WC n = Write character.
  •  !TEST = Get program code from input.

Comments

You can write comments by typing / anywhere in a line.

Input/output notations

You can put a value of accumulator, then values of stacks in square brackets (if not main stack, put number and equals), then any abstained teleports by ! and group number. For example:

  • 5[1,0,2][3=4,-1]!-4!-1!17 means that accumulator=5, main stack is (bottom to top) 1,0,2 and stack number 3 is 4,-1 and abstaned teleports are numbers -4,-1,17

The interpreter expects input in this format and gives output in this format as well.

Apply a program (function) to a value is like doing f(x) (if the function is called f), and the reverse (as in tac f_forward > f_reverse) is f'(x).

Examples

Infinite loop program:

/ Infinite loop program. Start accumulator at zero.
/ If accumulator is non-zero, it will not infinite loop.
/ f(0)=InfiniteLoop
/ f(x)=x if x>0
/ f(x)=x+2 if x<0 and x is even
/ f(x)=x-2 if x<0 and x is odd
TEL '#=0
IEDO
IODE
TEL 1

Countdown program:

/ Set accumulator to even number, and then it will put all number
/ onto stack n downto 2, count by 2.
/ f(4)=0[4,2]!4
/ f(5)=InfiniteLoop
/ f(6)=0[6,4,2]!6
TTG #
TEL '#=0 #
PP #
IODE
IEDO
TEL 1 #

Reverse order of the main stack:

/ Program to reverse order of stack.
/ Please start accumulator=0.
TTG 0
CMS
TTG #
TEL # #
CMS
SUBS
PP #
SWMS 0
PP #
SUBS
SWMS 0
CMS
TEL # #
SWMS 0
CMS
TTG #
CMS
TTG 0

External resources