esolang

refract

><> with blocks, a portal and stacks inside stacks.

Phase, 2015 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 8 known programs · Test method

Run it

Expected: hello world

The idea

Phase made refract in June 2015, after ><>, GolfScript and Portal. The program is a grid that wraps at every edge, and the pointer swims over it as the fish does in ><>, turning at arrows and mirrors. On top of that come blocks, which give one character a body of code, a portal the pointer can jump back to, and stacks that open inside other stacks.

Read the story

This implementation leaves out x, y and z. x sends the pointer off in one of eight directions at random, and y and z turn it onto diagonals in ways the specification gives only in part.

The machine

CommandDoes
> < ^ vPoint the way
/ \ | _ #Mirrors, as in ><>
! ?Skip the next cell; pop and skip it on 0
0 to 9, a to fPush 0 to 15
+ - * , %Pop x and y and push y op x; , divides with a fraction
= ) (Push 1 when y equals, is greater or is less than x, else 0
"..." '...'Push each character
: ~ $ @ rDuplicate, drop, swap, bring the third value up, reverse
[ ]Pop n and move the top n values to a new stack; pour it back
o n i jPrint a character or a number; read a character or a number
& g pMove a value to the register and back; read and write the grid
Ø OSet the portal; jump to it
{body}cMake a block named c
;Halt

Example

The Hello World.

The Hello World. It pushes the text, reverses it so h is on top, and goes down into a loop that prints one character per lap. m pushes 1 once the stack is empty, and only then does ? let the pointer reach ;.

Stacks inside stacks. 3[ moves the top three values to a new stack, r reverses only those, and ] pours them back.

Expected: 12543
Expected: 2.25

The portal example. The second test is true, so Ø sets the portal there, and O at the bottom sends the pointer back to it, still going down.

Expected: 2

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from refract

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run refract -e 'v;<
< ^'
shib manual refract

Source

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

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

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