Fraglets

Fraglets are a computational model based on chemical reaction. Fraglets represent both data, code, and computation. They flow through a system interacting with other fraglets along the way.

Core Instructions

The following operations form the basis of Fraglets:
dup [dup t a tail] → [t a a tail]
duplicate a single symbol
exch [exch t a b tail] → [t b a tail]
swap two tags
fork [fork a b tail] → [a tail], [b tail]
copy fraglet and prepend different header symbols
match [match a tail1], [a tail2] → [tail1 tail2]
two fraglets react, their tails are concatenated
matchp [matchp a tail1], [a tail2] →
   [matchp a tail1], [tail1 tail2]
"catalytic match", i.e. the matchp rule persists
nop [nop tail] → [tail]
does nothing (except consuming the instruction tag)
nul [nul tail] → []
destroy a fraglet
pop2 [pop2 h t a b tail] → [h a], [t b tail]
pop head element 'a' out of a list 'a b tail'
split [split seq1 * seq2] → [seq1], [seq2]
break a fraglet into two at the first occurence of *

Implementing Fraglets in Lua

Fraglets follow a rather simple eval modal. The first index of a fraglet is examined to see if it matches an opcode. If it does, that operation is evluated based on the above rules. Fraglets reach until no new products are created.

This simple eval model allows for constructing a naive runtime in about ~180 lines of Lua. For full parity with the existing runtime, the end total may be around ~300 lines. This implemention is not optimized and uses simple table manipulations.

beer 99.
matchp beer lt many-beer one-beer 1.
matchp many-beer exch b1.
matchp b1 exch b2 nul.
matchp b2 exch b3 *.

matchp b3 
    split message-1 
        bottles of beer on the wall! *
    split message-2 
        bottles of beer! *
    split message-3 
        take one down, pass it around, *
    split message-4 
        bottles of beer on the wall! *
    split match current-count 
        copy sum next-count -1 *
    split match current-count 
        copy build-message *
    split match build-message 
        match message-1 
        match build-message
        match message-2 
        match message-3 
        match next-count 
        match message-4
        message *
    split copy current-count.

matchp one-beer 
    split print 
        1 bottle of beer on the wall! 
        1 bottle of beer!
        take it down, pass it around,
        no more bottles of beer on the wall! 
    * nul.

matchp message split next-round * print.
matchp next-round match next-count beer.

What is the Eval Model

While inspired by chemistry and biology. Fraglets pose some interesting ideas for rewriting systems. The C runtime optimizes dispatch by using a prefix tree. This cuts down look up time and shuffling through irrelivant fraglets.

This optimized basis turns fraglets into a tree-based rewriting system. Fraglets under this model describe paths through the tree. Additionally, the tree acts as both your data store and your code base. Nodes in the tree can be excuted and even construct new rules by appending matchp to the root node.

Leaning into this model may produce some novel form for rewriting mutlisets without needing variables to capture values.