1Fish

From Esolang
Jump to navigation Jump to search
The title of this article is not correct because of technical limitations. The correct title is actually 1><>.

1><> (pronounced as "one fish") is a stack-based programming language based on Fish.

Overview

1><> is a 1-dimensional version of ><>. Its functionality is mostly the same, however some commands are altered.

Execution

Rather than a 2D playfield, it uses average style of writing programs, 1D. Because of this, there are no instruction pointer direction changes. The instruction pointer still exists, however it will not loop around at the end of the program, thus not needing an end program command. Any input is provided at the start, using the -i flag along with all the inputs. (e.g. ./1fish.py file.1f -i 43 2 7)

Stack

The stack can only contain numbers.

Commands

Any character that isn't valid will just be skipped. Space is a NOP.

Input, output, and arithmetic

0-9 Push the number onto the stack
+ - * / | ^ % Pops x (topmost) and y (second) and pushes y (operator) x. | is floor division (does division but ignores the remainder), ^ is exponent, and % is modulo (does division but returns only the remainder).
o Pop and output the Unicode character of the top item. If it's a decimal, round it.
n Pop and output the number of the top item (e.g. having 65 in the stack and using n will output 65, not A. Using o will do the opposite.)
i Take one character input, and push its value as a number. If no input is provided, push 0. (e.g. Code: in >> Input: A >> Output: 65)
" Toggle string parsing. If string parsing is enabled, push every characters' Unicode value onto the stack until disabled. This only works with double quotes.

Comparisons

< = > Pop x and y off the stack, and push 1 if y (operator) x is true. Push 0 otherwise.

Stack-based

Commands that revolve around the stack.

l Push the length of the stack onto the stack
d D Duplicate the top item or the whole stack, respectively.
c Remove the whole stack
r Reverse the stack
q Pop and discard the top item of the stack
s Swap the top 2 values of the stack

Conditional branching

{ } Runs the code inside of the 2 braces only if the top item (which gets popped) is non-zero. If the stack is empty, jump to the corresponding }. (Procedure: When the IP hits {, it will find the corresponding }. It will then pop the top value. If it's 0 or the stack is empty, jump to the }, otherwise, proceed inside.)
j Pop x and jump to position of x - 1 in your code. In other words, jump to AND RUN the command at position x.
( ) Repeat the code inside until the stack is empty, essentially creating a loop. Checks if the stack is empty at the end of the loop. If the stack is empty to begin with, skip everything inside.

Examples

Hello, world!

"Hello, world!"r(o)
>> ./1fish.py helloWorld.1f
Hello, world!

Interpreters

1fish.py

The one written by the author. Download will be up when it's actually done.