Object-Oriented Brainfuck (Hammy)
Object-oriented Brainfuck is an esolang by User:Hammy.
The making
There isn't variables in BF, so no objects. And there's no way to use two cell's values at the same time. So I added another tape. > and < now move the pointer on both tapes, and * (new command) switches to the other tape. Now we can make variables! ! creates a variable with the ID (not name) of the current cell on the current tape, and the value of the current cell on the next tape. Why "next tape"? Because * now goes to the next tape, and there's infinity tapes! This is looking like 2d memory... To make things possible, & goes back 1 tape. You can think of the commands *& as v^ with 2d memory. Anyways, where were we? Oh, yeah. Cells are now unbounded. A value of -1 is a "stop" value. It will make sense with : which is for object-making. It will take many values. Just see for yourself here, with 2d memory as the tape of tapes™. If the ToT (tape of tapes) looks like this (italic is current cell on pointer, red is current cell actually):
0 0 5 0 0
0 0 3 0 0
0 0 2 0 0
0 0 4 0 0
0 0 7 0 0
0 0 -1 0 0
then running : would make an object called 5 with content {3: 2, 4: 7}.
Alright, we have variables, but where'd they go? We have to find them using ? and ;. ? takes the current cell on the current tape as an argument, and sets the current cell on the current tape to the variable named (current cell value)'s value. ; takes 2 arguments; the current cell on the current tape (x) and the current cell on the next tape (y). It will take the key named (y)'s value in (x) and sets the current cell to it.
We have variables (and getting their values (and setting them with the same command as declaring)) and objects, so we need classes finally. () is a class container. It creates a class called (current cell value) and sets it to the values inside. {} declares a method. Classes can contain things other than method declarations, to run before declaring. Anyways, the pair of curly brackets declares a method called (current cell value) with the contents inside the brackets. The method 0 is the constructor. @ returns a value equal to the current cell. Inside the constructor method, @ instead returns an attribute. "'(x)'(y)" is the same as (), but extending upon (x).
Finally, object oriented BF.
Summary
BF, but <> now move all pointers on a tape of tapes and these commands are added:
| Command | What it does |
|---|---|
* |
Next tape |
& |
Previous tape |
! |
Declare or set a variable |
: |
Declare or set a variable to an object |
? |
Get variable |
; |
Get key from object |
() |
Class |
{} |
Method |
@ |
Return a value |
"''" |
Class, but extending off an existing class |
Examples
Soon...