BrainCurses
BrainCurses is a language derived from Brainfuck, using a deque instead of a tape for memory. Its name comes from the fact that programs usually resemble censored swearing in cartoons such as #@!*&@^!
.
Overview
BrainCurses programs have a deque and a single variable. The variable is referred here as A, the top of the deque is DT, and the bottom is D0. The instructions available only allow direct access to the top of the deque, much like a stack, but bottom items can be accessed by rotating the structure. The deque has unlimited size, and items are bounded or not depending on implementation. The commands are:
! = push a copy of A onto the deque @ = pop DT onto A ^ = rotate deque up (pop top item then push it at bottom) # = rotate deque down (pop bottom item then push it on top) + = increment A by 1 - = decrement A by 1 : = output A to the output stream ; = set A to next character in the input stream % = swap A with DT (equivalent to !^@# ) * = set DT to A (equivalent to !!^^@##@ ) & = peek DT onto A (equivalent to @!) [ = jump after corresponding ] if A==0 [$ = jump after corresponding ] if DT==0 (equivalent to %[% instructions %]%) ] = jump to corresponding [ or [$ _ = output A as a character 'n = set A to character n
Using an instruction that requires items present in memory when there are none is undefined.
Some instructions are simply included for convenience, as BrainCurses is not intended to be extremely minimalist, just odd to look at.
Examples
None of these programs are currently tested, as there is no existing implementation yet.
Hello World!
This program outputs "Hello World!"
!'H!'E!'L!!'O!' !'W!'O!'R!'L!'D!'!!##[$@_#]
Cat
This program outputs its input
;[_;]
String Reversal
If the string is 0 terminated, the following program will receive it from the input and output it reversed
[;!]#[$@_#]
Top Stack Addition
The following program adds the top two items on the deque and then pushes it on the top. The end result is identical to its original state save the fact that there will be a newly added item. I.E. it is non-destructive.
!^^&#!^&#!@[-%+%]#@
Computational class
The 'stack' in BrainCurses is actually as powerful as a deque, since the bottom element can be accessed using instructions ^
and #
. It is easy to emulate a tape using a deque; the following reduction from boolfuck is a formal proof that BrainCurses is Turing-complete, assuming -1, 0 and 1 are possible values for deque items.
boolfuck | BrainCurses |
---|---|
<program start> | !-!# |
+ |
@-![++%+] |
, |
;% |
: |
&: |
< |
[-]!#&+[^@#] |
> |
^[-]!^&+[#@^]# |
[ |
[$ |
] |
] |
This assumes that input is given as a stream of 0 and 1 values.
Implementation
An implementation in node.js, written by User:Conor O'Brien, can be found here.