BitFlip

From Esolang
Jump to navigation Jump to search

BitFlip is a language by User:Zzo38.

There are an unlimited number of variables that can store 1 bit each, and they can be named using numbers, letters, and the symbols -+_~'.

Commands

.var = Toggle value of var
?name = Go to the first ?name that matches this one and is constant
[var commands] = Loop while var is set
^name = Call subroutine at label ?name if it exists
% = Return from subroutine or stop program if not in one
& = Forget one entry from call stack

Pre-processor commands:

!name{commands} = Define a macro (name cannot include _ and ~)
,macro{parameters} = Run macro (parameters are separated by semicolons)
$number = When you run the macro, $1 is replaced by the first parameter, $2 by the second parameter, etc.
@number{parameter} = Repeat parameter number times
/*comment*/ = Comment

Expressions:

(var) = Returns _ if var is unset, ~ if var is set
<name> = Calls an external function and returns one bit, _ or ~
#_ = Returns ~
#~ = Returns _
#char = If char isn't _ or ~ then returns value of var called char

External functions for I/O:

<IN> = Input a bit
<OUT~> = Output 1, return 1
<OUT_> = Output 0, return 0

Examples

Copy input to output, forever (infinite cat program):

.1[1.<OUT<IN>>]

Display all characters 0 to 255:

!x{?_$1.$1^#$1$2%}!O{.<OUT#$1>}
.z[z,O{7},O{6},O{5},O{4}
,O{3},O{2},O{1},O{0}^_0]
,x{0;1},x{1;2},x{2;3},x{3;4}
,x{4;5},x{5;6},x{6;7},x{7;x}
?_x@8{&}%

Nested macros:

!create{!$1A{.$1$$1}!$1B{,$1$$1A{$$2}}}
,create{First}
,create{FirstSecond}
,FirstA{B}
,FirstB{Second;C}
/* Now these bits are set: FirstB FirstSecondC */

Compuational class

It is Turing-complete, because it is postible to translate every Smallfuck program to it

See also

Other languages operating on bits (implemented only):