Swapper

Swapper is a simple self-modifying reversible language invented by User:Tailcalled

Syntax
Swapper programs consist of a list of pseudo-assignments and special command(s):

program = statement program = statement [';' program] statement = pseudoassignment statement = pseudooperation statement = executecommand pseudoassignment = pattern '<->' pattern pseudooperation = integer operator integer operator = '<*/>' | '<+->' executecommand = '{' command '}' command = 'rev' pattern = pattern = integer constinteger = '[' number ']' integer = '(' number ')' number =

where atom is any list of alphabetic characters and number is a list of digits.

Integers
Integer literals are created by putting an integer in parenthesis

like: (42)

Pseudo-assignments
A pseudo-assignment is written like this:

A <-> B;

When this is reached, all occurrences of A will be replaced by B, and all occurrences of B will be replaced by A.

If one is an integer, it works the same way.

A <-> (42);

becomes

(42) <-> A;

after execution.

But anything inside or [these other brackets] will not be changed.

Constant integers
A constant integer literal is created by using brackets instead of parens.

[1337]

Constant integers can be pseudo-assigned, but cannot be pseudo-operated on.

A <-> [123];

becomes:

[123] <-> A;

after execution.

Pseudo-operators
Pseudo-operators must have both sides as integers, one a constant integer and one a normal one. When they are reached, all numbers in parenthesis will be changed in a certain way, but constant integers in brackets will not.

Multiplivision
If the control flow is going forward, this is multiplication. If backward, division.

(4) <*/> [3];

becomes (12) <*/> [3];

and going backward it will again become

(4) <*/> [3];

because 12 was divided by 4.

Addtraction
If the control flow is going forward, this is addition. If backward, subtraction.

Special Commands
Special commands are written inside angle brackets. Letters in angle brackets can not be replaced by pseudo-assignments

rev
The control flow gets reversed when 'rev' is reached.

A and B will be switched twice, doing nothing.

A <-> B;   ;

prtmd
toggles print mode. Whenever an atom and an integer are switched, the integer is printed to standard output.

Print hello in leet.

out <-> (3110);

Prints "3110".

Sample Programs
Increment.

i <-> (0); i <+-> [1]; out <-> i;

Step by step

1. All i's replaced by (0)

(0) <-> i;   (0) <+-> [1]; ;   out <-> (0); ;

2. All (0)'s incremented.

(1) <-> i;   (1) <+-> [1]; ;   out <-> (1); ;

3. enter print mode.

4. "1" printed because it is in print mode.

5. printmode turned off.

Extensions
The language is currently not very powerful, so Tailcalled encourages everyone to propose more instructions that will make it more powerful while keeping it reversible.