Swapper is a simple self-modifying reversible language invented by User:Tailcalled in February of 2012.
Swapper programs consist of a list of statements separated by semicolons:
program = statement [';' program] statement = <atom> '<->' <atom> statement = '(' <#> ')' ('<+->' | '<*/>') '[' <#> ']' statement = '<rev>' statement = '<prtmd>'
where <atom> is a string of characters in the groups A-Z, a-z, or 0-9, and <#> is just in the group 0-9.
Integer literals are created by putting an integer in parentheses.
Constant integer literals are created with brackets instead. These have the property of remaining unchanged during a pseudo-operation.
Operators are enclosed in angle brackets and self-modify the program when executed. They cannot be modified themselves.
||swaps all occurrences of A and B, where both are alphanumeric patterns delimited by ; and <->. Invalid characters (spaces, newlines, symbols, etc.) are skipped in the pattern. Text inside  or <> remains unchanged during the swap.|
||replaces (x) with (x+y) if the program flows forward, and (x-y) if backward.|
||replaces (x) with (x*y) if the program flows forward, and (x/y) if backward, rounding down.|
||reverses program flow.|
||toggles "print mode". In this mode, any number that |
Additional operators can be added at the programmer's discretion. User:Tailcalled encourages this notion to add power to the language while maintaining its reversibility.
This program prints 1 to STDOUT.
i <-> (0); i <+-> ; <prtmd>; out <-> i; <prtmd>;
Step by step:
is are swapped with
(0) <-> i; (0) <+-> ; <prtmd>; out <-> (0); <prtmd>;
(0)s are incremented.
(1) <-> i; (1) <+-> ; <prtmd>; out <-> (1); <prtmd>;
3. Enter print mode.
4. 1 printed because it is in print mode.
5. Exit print mode.
Print the ASCII #s of Hello, world!
<prtmd>; out <-> (72); out <-> (101); out <-> (108); out <-> (108); out <-> (111); out <-> (44); out <-> (32); out <-> (119); out <-> (111); out <-> (114); out <-> (108); out <-> (100); out <-> (33); out <-> (10);