Rui is a thread-based esolang created by User:Sinthorion. All control flow and even basic arithmetic requires the use of multiple threads that create, communicate with, and destroy other threads. Each thread stores a single unbounded integer as value for data storage and to distinguish it from other threads.
The source code (file extension
.rui) is a single file with one or multiple lines of code. Newly started threads always start at the beginning of one line that has been specified when creating the thread, and run through the rest of the code until they get terminated. Newly spawned threads have the value 0.
Execution happens in cycles. In each cycle, each thread executes one instruction. The order in which threads execute within a cycle is implementation-dependent; in the provided standard implementation, older threads always execute before younger threads. Newly created threads need to wait until the next cycle before first executing.
Disclaimer: This language is still young and every detail of it is subject to change.
The language currently features these instructions:
=<value>sets value of current thread
+<line>spawns a new thread which starts execution at the specified code line
*<line>spawns as many threads as this thread's value, which start execution at the specified line
-<value>kills all other threads with the specified value; sets own value to amount killed
rreads a number from STDIN into current thread value
wwrites thread value to output
!stops execution and kills thread
#comment until end of line
.sleep for one tick (each thread executes one instruction each tick, in the order they were created in)
$adds this value to all other threads
~remove this value from all other threads
:<line>jump to line
Some instructions may be followed by a number as parameter. These numbers must consist of one or more digits (an no other characters) and immediately follow the instruction. Line numbers are 1-based, so 0 is invalid as `line` parameter, but valid as `value` parameter.
IO works in numbers. Implementations might choose to have ASCII IO instead.
Read two numbers and print the sum
Print all Fibonacci numbers:
Explanation: This starts with two threads (
+2), with values 0 and 1 (
=1). Each thread then first waits to sync with other threads (
.), then writes its value (
w), spawns a new thread (
+2) and adds its value to all other threads (
$). Precise timing, as in most Rui programs, is critical.
An example implementation in Ruby is found here.