~
~ is an esoteric programming language created in 2006 by User:Tim_pettit. The basis of this language is to manipulate data on a single deque using only unary and ternary operators.
Syntax
All statements consist of a single operator followed by a "|" character to delimit each. (where ever x, y or z are used they should be replaced by only ^, & or an unsigned integer constant) (if people like the language ill post an interpreter so people can see the programs work)
The Ternary Operators: There are two ternary operators in ~ they are ! and # followed by three values delimeted by spaces.
! x y z|
is equal to the c statement:
if(x == y) push_front(z); else pop_back();
# x y z|
is equal to the c statement:
if(x == y) pop_front(); else push_back(z);
The Unary Operators: There are six unary operators in ~ they are +, -, ++, --, +- and -+.
+x|
is equal to the c statement:
pop_front(); push_back(x);
-x|
is equal to:
pop_back(); push_front(x);
++x|
is equal to:
push_back(pop_back() + 1); push_front(x);
--x|
is equal to:
push_front(pop_front() + 1); push_back(x);
+-x|
is equal to:
push_front(pop_front() + x); push_back(pop_back() - x);
-+x|
is equal to:
push_front(pop_front() - x); push_back(pop_back() + x);
With the operators there are also five Keywords represented as the symbols: ^, &, $, % and ~.
^: peek at the front of the deque &: peek at the back of the deque $: pop the front of the deque to stdout as a char and push a value from stdin (if there is no input 0 is pushed) onto the back. %: pop the back of the deque to stdout as an int and push a value from stdin (if there is no input 0 is pushed) onto the front; ~: swap the front and back values on the deque.
~ also has two loops which are used by encasing the code to be looped in the correct pair of brackets, either { } or [ ]. { }: works like a c while loop, it loops until the front of the deque is equal to zero, the condition is checked at the start of the loop.
while(peek_front() != 0) { /* do stuff */ }
[ ]: works like a c do loop, it loops until the back of the deque is equal to zero, the condition is checked at the end of the loop.
do { /* do stuff */ } while(peek_back() != 0);
Along with all this ~ allows unsigned integers to be entered as constants in the source code, however the deque is signed.
Sample Code
Here are two sample programs. The Mandatory Hello World
! 0 0 0 | ! 0 0 33 | ! 0 0 100 | ! 0 0 108 | ! 0 0 114 | ! 0 0 111 | ! 0 0 87 | !0 0 32 | ! 0 0 111 | ! 0 0 108 | ! 0 0 108 | ! 0 0 101 | ! 0 0 72 | { $ }
and A Cat Program
! 0 0 1| ! 0 0 1| # 0 1 0| { ~| $| ! 0 0 &| ++ 0| ~| ! ^ 0 0| # 0 0 0| ~| }