esolang

Grin

Brainfuck with a register and a pocket calculator, so that programs fill up with smileys like :).

Madk, 2010 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: Calculate how many numbers of the Fibonacci sequence? 0 1 1 2 3 5 8 13 21

The idea

Madk made Grin in 2010 to keep the fun of brainfuck and add more powerful maths. The tape holds real numbers instead of bytes, and next to it sits one register. Most commands combine the current cell with the register: add, multiply, divide, raise to a power, take a logarithm. Others are a calculator's keys, sine, square root, pi.

Read the story

Text output got easy too. (Hello, world!) prints the text between the brackets, and a lone ) prints a newline. Printing a number and then a newline is :), which is where the smileys and the name come from. Any brainfuck program still runs once + and - are written as } and {.

The machine

CommandsDo
> < [ ] } {As in brainfuck; add or take 1
$ \ ~ = _Cell to register; register to cell; swap; clear the register; clear the cell
+ - * / ^ % L mCell with the register: sum, difference, product, quotient, power, remainder, log, mean
. : ' " , ;Print the cell or the register as a character or a number; read a character or a number
(text) )Print the text; print a newline
s c t S C T DTrigonometry, in degrees until D
q l e p 1 2 r @ ? & \| !Square root, ln, e, pi, reciprocal, mod 2, round, negate, sign, nand, or, not
j ` #...# | Skip as many commands as the register says; end; a comment

Example

The Fibonacci program from the specification.

The Fibonacci program from the specification. Cells 1 and 2 hold the last two numbers; the loop adds them in cell 3 through the register, prints the sum with :) and shifts the pair along.

Expected: Hello, world!

The specification also has a factorial. It multiplies correctly, then moves one cell too far and prints the 0 that is there.

Further

Ideas it shows

Grin builds on Brainfuck.

Brainfuck derivatives

Cell-based

Write your own in Run Convert a program from Grin

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: grin.

Command line

shib run grin -e ',[.,]' --input 'grin'
shib manual grin

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/grin.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org