Weave

From Esolang
Jump to navigation Jump to search

Weave is a concurrent dialect of brainfuck. The original specification was written by Seven Inch Bread.

Brainfuck translates particularly well into concurrent programming, which can be attributed to its simple design and execution procedure.

Specification

Weave consists of a list of Brainfuck-like programs being run concurrently. Each program is read command by command at roughly the same time (well... a command from a program at the top of the list is read before a command from a BF program below it, but they are all interpreted close to the same time)

Each thread has its own private array, which only it has access to, as well as access to the public (or global) array. The private array allows separation of concern and local scoping, while the global array allows sharing of data.

Syntax

A ! denotes the beginning of a thread, while a ; marks the endpoint.

!<thread1>;!<thread2>;!<thread3>; ... ...

For readability, it is sometimes desirable to use newlines to separate the threads as well...

!<thread1>;
!<thread2>;
!<thread3>;
...
...

This is useful to imagine the order of events as they occur.

The following are commands that may occur in the body of a thread:

> - Increment the array pointer
< - Decrement the array pointer
+ - Increment the value of the pointed cell of the current array (see ~)
- - Decrement the value of the pointed cell of the current array
. - Output the ASCII value of the pointed cell of the current array.
, - Store user input in the pointed cell of the current array 
[ - If current cell is 0, skip to the corresponding ]
] - if the current cell is not 0, return to the corresponding [

~ - Toggle between the global or private array.

All characters outside of a thread are ignored, and all characters in a thread that aren't commands are treated as a NOP.

Computational class

Because brainfuck is a subset of Weave, it can be easily proven that Weave is a Turing-complete language.

Implementations

weave.rb is a ruby interpreter for Weave (and Brainfork and pbrain and brainfuck). Note that this implementation uses only semicolons as thread spawn points, as the exclamation mark(!) is used in brainfuck to attach input to the tail of a program.