Quipu

Quipu is an esoteric programming language inspired by Quipus (also known as "talking knots") – recording devices historically used by Incas. Quipu was originally designed by Vladimir Kostyukov in Jan 2013.

Specification
A program in Quipu is represented by vertical threads (cords) that contain various types of knots. The number of threads is unlimited as well as the number of knots on each thread. All knots of every thread should be aligned to the same indentation level from the beginning of the source file.

Both types of Quipu entities (threads and knots) have values and can be evaluated. Knots evaluate by themselves, threads by reference knot evaluating. The self values of threads are stored in the zero knots. It allows to use self values as implicit argument in calculations.

Data Types
There are two simple data types available in a Quipu program: big integer numbers and strings.

Comments
Quipu supports multiline comments that start with " and end with ". Comments are allowed only in the beginning of the source file. The typical use case for comments is labeling the Quipu threads by numbers to increase the readability of the program.

Program Execution
Before executing the values of all threads are  (zero).

Execution starts with the first thread (then the second, etc.). At each step of execution the current knot is evaluated. The execution continues until the last knot of the last thread has been evaluated, or a halt knot is evaluated.

When jumping, the value of a thread is assigned to the value of the last evaluated knot in the thread.

There are two reasons for jumps:
 * All knots of the current thread have been evaluated (jump to next thread).
 * Evaluation jumps knot (jump to specified thread).

There are two ways to get an exception during the execution of a Quipu program:
 * Referencing (with the  knot) a nonexistent thread;
 * Jumping to a nonexistent thread.

Knots Table
Let  be the number of the current knot and   be the value of the current knot.

Hello World!
'H 'e 'l 'l 'o ' 'W 'o 'r 'l 'd '! \n /\

Cat program
\/ /\

Prints the numbers from 0 to 99
"0 1  2" 1& 1& 1& [] ++ [] /\    1% \n    -- /\   3&        ==          0&       ??

Calculates the sum of numbers from 0 to 99
"0 1  2  3" 1& 1& 1& 0& [] ++ [] [] ++    1% /\       --       3&       ==       0&       ??

Calculates the factorial of given number
"0 1  2  3  4  5  6" \/ 2& 1& 4& 1& 1& 1& 6& [] -- [] ^^ [] /\ == ** 0& 4& -- /\        1& [] == 1& ::     -- -- 2& >>            4& 4& []               [] [] 1&               ** ** >>              1& 0&    ++ []       ++

Prints the first N members of the Fibonacci sequence
"0 1  2  3  4  5  6  7  8" \/ 1& 3& 4& 3& 7& 3& 1& 7&    -- [] [] [] [] [] ^^ []    0&    1& 2& 6& /\ -- 7&    []    -- [] == 7& 1& >>    --    7& ++ ', [] >> '.    7&    []    /\ 1&    /\    []    **    '  >>    **    1&    /\    0&    ++    []    ++    8&    ==

99 bottles of beer
"0 1 2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20 21" 'n 'N '  '  's '  '  ', '. 'T 'G 1& 1% 1@ 1@ 9& 2& 9& 1& 9& 1& 1@ 'o 'o 'm 'b   'o 'o '  \n 'a 'o ++ ;; 2& 2& [] /\ [] /\ [] [] [] 'o 'o   'f 'n       'k '     1@ [] [] /\ 3& /\ 3& /\ /\ /\ 'r 't   '  '        'e 't    1& 2& /\ 7& [] 7& [] 7& 2& 7& 'e 't   'b 't       '  'o    [] -- 3& [] /\ [] /\ [] [] [] 'l   'e 'h       'o '     -- 1@ [] /\ 4& /\ 5& /\ /\ /\ 'e   'e 'e       'n 't       6& /\ 1@ [] 1& [] 0& 3& 9@ 'r '       'e 'h       == 4& 2& /\ /\ /\ [] [] 9& 'w      '  'e          [] [] 5& 3& 6& /\ /\ /\ 'a      'd '           /\ 1& [] [] [] 2& 4& 3& 'l      'o 's          5& -- /\ /\ /\ [] [] [] 'l      'w 't          [] /\ 6& 5& 7& /\ /\ /\ 'n 'o         /\ 3& [] [] [] 3& 5& 4& ' 'r          6& [] /\ /\ /\ [] [] [] 'a 'e         [] /\ 7& 6& 1& /\ /\ /\ 'n '          /\ 4& [] [] /\ 4& 6& 5& 'd 'a         7& [] /\ /\ 3& [] [] [] ' 'n          [] /\ 2& 8& [] /\ /\ /\ 'p 'd         /\ 5& /\ [] /\ 5& 7& 6& 'a '          1@ [] 3& /\ 5& [] [] [] 's 'b         2& /\ [] \n [] /\ /\ /\ 's 'u         [] 6& /\ /\ /\ 6& 0& 8& ' 'y          /\ [] 4&    8& [] [] [] 'i '          3& /\ []    [] /\ /\ /\ 't 's         [] 8& /\    /\ 8& 2& ' 'o          /\ [] 5&       [] [] 'a 'm         4& /\ []       /\ /\ 'r 'e         [] \n /\       \n 3& 'r '          /\ /\ 8&       /\ [] 'o 'm         5& 1@ []          /\ 'u 'o         [] 1& /\          4& 'n 'r         /\ ?? []                           'd 'e          8&                /\ []               5&                                           /\                []                                                             /\                                                             8&                                                             []                                                             /\

Exponentiation
This program takes two numbers a and b and calculates a to the power of b.

"0 1  2  3  4  5  6  7  8  9 10" \/ \/ 5& 7& 5& 1& 7& 1& 1& 7& 3&       [] [] [] 8& [] 8&    [] []       1& 2& 5& [] 2& []    1@ /\       -- %% [] -- // --    ==          2& ** 0&    1&    2&          []    []    []    ??          **    **    **          1&    4&    6&          ++    []    []          ^^    ++    ++          **          1&          --          8&          []          **          1&          ++

Implementations

 * Reference implementation in Scala (GitHub)
 * Esoteric IDE that supports Quipu (GitHub)