Fish

><> (to be pronounced as /ˈfɪʃ/) is a stack-based, reflective, two-dimensional esoteric programming language. It draws inspiration from among others Befunge. It was invented by Harpyon in 2009.

Concepts
><> is a two-dimensional language, meaning the code is not necessarily executed in a linear manner. Using various instructions, the direction the code is read can be changed to either up, down, left or right. It is also a stack-based language, so all operations are performed on a stack. You can also store and retrieve values in the codebox, so making a proper compiler is very hard, if not impossible.

What makes ><> unique is the fact that it supports multiple stacks. A program starts off with one stack, where values are pushed and popped. The program can however create a new stack on top of the original one, with a specific amount of values moved over from the original stack. The program can create as many new stacks as it wants to. When a stack is removed, the values residing on it are moved to the top of the underlying stack. Example here. Each stack is effectively a new scope in the program; this allows for writing functions and snippets to drop into code easily.

Code execution
><> code is laid out in a two-dimensional codebox. The codebox is infinite in all directions, positive and negative. It is traversed by the instruction pointer, or the IP.


 * Note: all coordinates for the codebox are given as (character,line), i.e., (column,row).

The instruction pointer starts out at (0,0), i.e. the top-left of the script. It initially moves towards the right, but its direction can be changed using a variety of instructions. When the IP reaches the end of the code in any direction, it will wrap around, or "jump" to the opposite side. The IP will never reach the negative side of the code; this makes this space useful for storing values. Execution will not stop until a  instruction is met, or an error occurs.

In the following example, the IP moves downwards, leftwards, wraps around to the right side, goes upwards, then leftwards, and stops.

v ;< < ^

Mirrors
Mirrors are special kinds of instructions that will change the direction of the IP depending on the direction it already has. For example, if the IP is moving rightwards and meets a  instruction, it will be "reflected" (unrelated to reflection) downwards. If the IP meets it going downwards, it will be reflected to the right, and so on. Meeting  horizontally or   vertically equals a NOP, but meeting them vertically and horizontally, respectively, will invert the direction, and   will do so unconditionally.

Stacks
><> is stack-based, and thus every instruction except movement-related and the end-execution instruction do something to the stack. You can push numbers and input, perform modifications and pop output using various instructions. You can also create new stacks, this using the  instruction. Creating a new stack pulls a specified number of items from the current stack onto the new one. The new stack is completely isolated from the previous one, and an arbitrary amount of stacks can be created on top of each other. When the  instruction is met, the current stack is popped and its values are moved back to the underlying stack. If the current stack is the last stack,  simply empties the stack and registry.

12345 3[ r  ]  rnnnnn; ^   ^  ^  ^     ^   |    |  |  |     | Output: 12543. The three top values were reversed! |   |  |  |   |    |  |  | The second stack is removed, putting its values back to the first stack. |   |  |   |    |  | The second stack is reversed. |   |   |    | A second stack is created, pulling 3 values from the first stack |  | Numbers 1-5 are pushed onto the first stack.

The register
The  instruction is used to store and retrieve values in a register. If the register is empty,  stores a value in it. When the register holds a value,  pushes it back onto the stack.

When creating new stacks, new registers are also created. However, the values aren't moved around; each stack starts off with an empty register, and when the stack is removed, the register is dropped.

Input/output
><> has three input/output instructions:  for input and  /  for output. The  instruction simply reads a character from stdin. If no more input is available,  pushes. Note that there is no instruction to input a number, you will have to parse the characters yourself.

While parsing numbers is not very hard, it makes for slow and possibly glitchy programs. Most programs requiring number input reads it from the stack at program start. This is done with an interpreter that supports pre-populating the stack with values. Doing so with the fish.py interpreter looks like this:

$ ./fish.py --code "2*n;" --value 10 20

Output is a bit easier, as you have two instructions:  and. They will pop a value and output it as a character and a number, respectively. The output is naturally written to stdout.

Errors
The following events will cause an error in ><>:


 * Division by zero
 * Reaching an invalid instruction
 * Trying to pop or modify on the stack when it is empty or has too few values
 * If the interpreter does not support arbitrary-precision numbers, an overflow results in an error

Although there are multiple reasons an error may occur, there is only one error message: something smells fishy...

Instructions
The following is merely a draft of the instructions in ><>, and is subject to change.

Input/output
See Input/output.

Reflection/miscellaneous
The space character is simply a NOP and is allowed anywhere.

Examples
All the examples are executed using the fish.py interpreter.

Hello, world!
"hello, world"r\ o;!?l<

$ ./fish.py helloworld.fish hello, world

FizzBuzz
0voa                           ~/?=0:\ voa           oooo'Buzz'~<     / >1+:aa*1+=?;::5%:{3%:@*?\?/'zziF'oooo/ ^oa                n:/

$ ./fish.py fizzbuzz.fish 1 2 Fizz ... 98 Fizz Buzz

Fibonacci sequence
Outputs Fibonacci numbers until stopped. The execution is slowed down using, to avoid being spammed to death with the endless Fibonacci sequence. 10::n' 'o&+&$10.

$ ./fish.py fibonacci.fish -t 0.01 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 ...

Lucas sequence
Outputs the Lucas numbers until stopped. 2n' 'ol?/21>::! $&+&\ /

$ ./fish.py lucas.fish -t 0.01 2 1 3 4 7 11 18 29 47 76 123 199 322 521 843 1364 2207 3571 5778 ...

Factorial
Calculates the factorial of the input number. Assumes the input is a non-negative integer. Notice that the input value,, is supplied using the -v switch of the interpreter. :?\~11>*l1\ -1:/ ;n\?- /

$ ./fish.py factorial.fish -v 10 3628800

Quine
Outputs its own source code. "r00gol?!;40.

$ ./fish.py quine.fish "r00gol?!;40.

Square root
A function (isolated stack; remove the  and   instructions to create "inline" version) that calculates and outputs the square root of the top of the stack/input number. 1[:>:r:@@:@,\; ]~$\!?={:,2+/n

$ ./fish.py sqrt.fish -v 64 8

Brainfuck interpreter
v 1 0           >$    >$                 \ >:@$:@i:0(?^$:2=?^$:3b*-0=?\v/      >:&$:1=?v>$@p&0(?v$1+ \                 02]p00<> :'+'=?^\      $$       >1-0p \01-\                      /^?='>': <      d+ v   <}            v?= \     > :'<'=?^\      %e v}]p$p4r}:r:$4[2@:/f1+/    /^?='-': <      \/ >{1+:00g=?\:1g:e-?^~:}0a. > :'['=?^\ /    -1-:/                 /^?=']': < >1+:00g=?;:1g0$. > :'.'=?^\ ^            ~<   $\.51$ ~^?=',': <  '['~ 20g:3g  ?^>$4g^ ']'~ 20g:3g0=?^^ ^                <     \  '+'~ 20g:3g1+3$@p^ ','~ 30g:1+30p2g 20g3p/ '-'~ 20g:3g1-3$@p^ '.'~ 20g3go     / '<'~ 20g1-20p\ ^            <  '>'~ 20g1+20p/

echo '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.--..>>+.>++.' | ./fish.py brainfuck.fish Hello World!

echo '-,+[-[>>++++[>++++++++<-]<+<-[>+>+>-[>>>]<>+<-]>>+>]<<<<<->>>[-]+>--[-[<->+++[-]]]<[++++++++++++<[>-[>+>>]>[+[<+>-]>+>>]<<<<<-]>>[<+>-]>[-[-<<[-]>>]<<[<<->>-]>>]<<[<<+>>-]]<[-]<.[-]<-,+]!Esolangs' | ./fish.py brainfuck.fish Rfbynatf

fish.py
The "official" interpreter, or the one written by the author. The latest version is available here. Requires python versions 2.7 or 3.2 or later. For usage information, run it with the --help switch.

http://fishlanguage.com
An online interpreter, written in Javascript. Features animation of the instruction pointer moving through the program. The interpreter works well, but the site is work-in-progress, and may be slow.

go-fish
An interpreter written by redstarcoder. It follows the same behaviour as the fish.py interpreter, but can also follow the fishlanguage.com behaviour with "-m" set. Download at GitHub.

fish.java
An interpreter written by Charlie Bouthoorn. It has the same console arguments as the "official" interpreter. Get the source from GitHub here.

fishr
An interpreter written in Rust, by Marc Noirot. It has roughly the same console arguments as the "official" interpreter. Get the source from GitHub here.

Older interpreters
The following interpreters were written towards an older version of ><> that featured multithreading. The multithreading capabilities were removed and replaced with multiple stacks support, which was deemed more useful (not that esoteric languages are useful in the first place). These interpreters may not work with some updated instructions, like,   and. You can of course still use these interpreters using the old documentation.

Python
The old version of the official python interpreter is available through Gist.

Invoke it by first making sure you have installed python, and typing  into your system's command line. Script is replaced with a .fish file, and tick is optional and defines a delay in seconds between each instruction, to slow down execution for debugging etc. It should work with both python 2.x and 3.x, as well as both Windows, Linux and Mac.

Delphi
Another interpreter, written in Delphi, is a result of a so-called 'code-golf challenge'. It interprets every instruction (except the threading related instructions) in about 1290 characters of source code. (A version with threading support is also available on the same site.) Get it here!

Compile the code into a console application with any Unicode-enabled version of Delphi (a port to the FreePascalCompiler FPC is trivial). Invoke the resulting executable and supply the path to a .fish file on the command line. Speed can be limited by increasing the Sleep time in the code.

More
There are several interpreters in a multitude of languages available in the StackExchange code-golf challenge.