4 ms·
This is one of the ideas I'm working on integrating into my toy data/programming language, Fern. https://github.com/andrewf/fern https://github.com/andrewf/fern
by andrewflnr 15y ago
This is one of the ideas I'm working on integrating into my toy data/programming language, Fern. https://github.com/andrewf/fern https://github.com/andrewf/fern. It's not apparent from the README, but if you modify a Fern structure in memory, all dependent values will (should) be updated, even with name references pointing back up the hierarchy of data structures. These are mostly lists and maps (which define names for subsidiary structures), which can be generated by constructs like conditionals, functions, and (someday) loops.
Besides the ideas I listed, I see it being used in scenarios where you have formulas based on a few inputs, and want to see what the output looks like when you mess with stuff, like physical dimensions in a design or financial stuff.
It's nice to have a real term for this sort of thing in "reactive document" or "reactive programming" or what have you. Not so nice to realize my idea isn't unique and brilliant. :)
- scarmig 15y agoHow does this work? Is it simply a shit ton of Observers?
- andrewflnr 15y agoBasically, a dirty flag that is checked every time you try to read a value. More specifically, each object has a self.value attribute that serves as a cache of the object's content. When it is notified that something has changed, it deletes the value. When you access it, it recomputes itself from scratch, taking advantage of caches of subobjects where possible. You can see most of the logic in fern.ast.node.Node. self.refresh_impl is supposed to set self.value in a way appropriate to the subclass, and the Node functions handle the rest. This is actually a pain to debug, especially with lots of nested scopes, but it seems to me like the evaluation should be lazy, rather than changing one object potentially re-computing the entire tree when you only cared about one part. You can call .refresh() on it manually if you need to get the computation out of the way.
- kragen 15y agoIt sounds like Cells or the Trellis.
- andrewflnr 15y agoWhat "Cells" are you talking about? Trellis looks cool; thanks for the tip.
- kragen 15y agoThe original one was http://common-lisp.net/project/cells/ http://common-lisp.net/project/cells/. You may also be interested in http://en.wikipedia.org/wiki/Reactive_programming http://en.wikipedia.org/wiki/Reactive_programming and http://en.wikipedia.org/wiki/Dataflow_programming http://en.wikipedia.org/wiki/Dataflow_programming.
- andrewflnr 15y agoYes indeed. Thank you.
- Too 15y agoSounds a bit like what they in .NET, especially WPF, call DataBinding? I.e a control can display a mirror of a variable/property without much manual intervention.
- andrewflnr 15y agoThey're similar, but I think Fern takes a pretty different perspective.