JSMeth

From Esolang
Jump to navigation Jump to search

JSMeth is a JavaScript implementation of brainfuck. The commands are the same, but they're expressed as JS methods.

Syntax

The syntax is simple. The language only includes a Stack object, with the following methods, all of which return the Stack itself upon calls. The Stack behaves like a tape, and is a bit of a misnomer.

Method Result
.moveLeft() Moves the stack pointer to the next cell.
.moveRight() Moves the stack pointer to the previous cell.
.inc() Increments the value of the cell by 1.
.dec() Decrements the value of the cell.
.loop(f) Executes the function f while the value of the current cell isn't 0.
.out() Outputs the value of the current cell.
.in() Accepts one byte of input and stores it to the current cell.

Example

Adder

The adder in BF is ,>,<[->+<]>.. The equivalent JSMeth code is Stack.in().moveRight().in().moveLeft().loop(function(){this.dec().moveRight().inc().moveLeft();}).moveRight().out();

Hello World

The HW program in BF is ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++..

In JSMeth, it's

  Stack.inc().inc().inc().inc().inc().inc().inc().inc().loop(function(){this.moveRight().inc().inc().inc().inc().loop(function(){this.moveRight().inc().inc().moveRight().inc().inc().inc().moveRight().inc().inc().inc().moveRight().inc().moveLeft().moveLeft().moveLeft().moveLeft().dec();}).moveRight().inc().moveRight().inc().moveRight().dec().moveRight().moveRight().inc().loop(function(){this.moveLeft();}).moveLeft().dec();}).moveRight().moveRight().out().moveRight().dec().dec().dec().out().inc().inc().inc().inc().inc().inc().inc().out().out().inc().inc().inc().out().moveRight().moveRight().out().moveLeft().dec().out().moveLeft().out().inc().inc().inc().out().dec().dec().dec().dec().dec().dec().out().dec().dec().dec().dec().dec().dec().dec().dec().out().moveRight().moveRight().inc().out().moveRight().inc().inc().out();