esolang

Crochet

Every node is a thread that holds one number. It spawns children by name and folds in what they hand back.

Stareye, 2024 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 6765

The idea

Stareye made Crochet in 2024. A program is a set of named nodes, and a node is a wrapper around one 64-bit unsigned number. A node works by spawning other nodes and by reacting each time one of them finishes. In the specification every node runs on its own thread, so nothing fixes the order in which the children report back.

Read the story

Recursion falls out of this. The fib node spawns two fib children, one with its number minus 1 and one with minus 2, and adds up what they return.

The machine

Each node has a spawn block and a pop block of rules, written match -> actions. The match is a number, or _ for every other number.

ActionDoes
20Set the node's number
@Set it to the value the rule matched
&Set it to one byte of input
+1 -@Apply the operator to the number
!Print the number on a line of its own
fibSpawn the node with that name

A new node runs the spawn rule that matches its parent's number at the moment it was spawned. When a child finishes, the parent runs the pop rule that matches the child's last number. A node finishes when its rule is done and all its children have finished. The run starts at origin and ends when origin finishes.

Example

The example computes the 20th Fibonacci number with 21,891 fib nodes.

The example computes the 20th Fibonacci number with 21,891 fib nodes.

The truth machine reads one byte. On 0, which is byte 48, it prints 0 and stops. On 1 it spawns act after act and prints 1 for ever.

Expected: 0

The silly example spawns one and two and keeps whichever reports back last, so the specification cannot say what it prints. This implementation runs one event at a time in the order the events arose, so two always reports last.

Expected: 2

Patterns it teaches

  • Nondeterminism: the order in which the threads finish decides the result.

Further

Nondeterministic

Write your own in Run Convert a program from Crochet

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: crochet.

Command line

shib run crochet -e 'origin
    spawn
        _ -> & act
    pop
        _ -> 0

act
    spawn
        48 -> 0 !
        _ -> 1 ! act
    pop
        _ -> @' --input '0'
shib manual crochet

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/crochet.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org