The current way to do cyclical graph structures is broken. It works by setting the value of atoms within reactions. This violates Havelock's three central tenets:
derivations are always lazy
derivations are always consistent
derivations require no manual memory management
Using a reaction to propagate state ruins all the of these. The laziness goes away because reactions are eager by definition. The consistency goes away inside transactions because reactions don't run inside transactions. There are other very subtle consistency problems outside of transactions which aren't worth enumerating here. Finally, the automatic memory management doesn't apply for reactions so that goes out the window too.
I think I figured out how to fix this. It involves creating a new derivation type which I'll call loop nodes for the time being. I've got some of the details written down in a notebook, I'll try to get around to the typing them up later.
The API would look a bit like this:
const a = atom("");
const as = a.derive(a => a + "a").loop(a).protect(5)
as.get();
; => "aaaaa"
After thinking about this a bit more I can't seem to reconcile consistency with automatic memory management for cycles. I can get one or the other, but never both.
The current way to do cyclical graph structures is broken. It works by setting the value of atoms within reactions. This violates Havelock's three central tenets:
Using a reaction to propagate state ruins all the of these. The laziness goes away because reactions are eager by definition. The consistency goes away inside transactions because reactions don't run inside transactions. There are other very subtle consistency problems outside of transactions which aren't worth enumerating here. Finally, the automatic memory management doesn't apply for reactions so that goes out the window too.
I think I figured out how to fix this. It involves creating a new derivation type which I'll call loop nodes for the time being. I've got some of the details written down in a notebook, I'll try to get around to the typing them up later.
The API would look a bit like this: