beginners 2025-11-04

Is the idea of “Observers/Observables” or anything analogous to it extant in clojure or clojure design patterns?

It sort of depends on what you mean by "Observer/Observables". • There are lots of reactive options using signal-like things (eg. https://github.com/leonoel/missionary, https://github.com/hoplon/javelin, https://github.com/kennytilton/matrix, https://day8.github.io/re-frame/subscriptions/, https://reagent-project.github.io/). • A related idea is having values, derived values, and a system that keeps them in sync (eg. https://github.com/oakes/odoyle-rules, https://www.clara-rules.org/, https://github.com/wotbrew/relic). • As mentioned, all ref types have add-watch.

The reason I ask is because I am working in c++ right now and the place I work for has ‘_today’, among other things, which is available as an observable where the Observer basically gets called at midnight every day automatically and updates it to the appropriate daily value. I don’t totally understand how it operates automatically at midnight and I want to better understand the idea of an observer and observable (because it’s also used a lot in less trivial ways throughout the code too) and understanding things in clojure terms has tended to make me a better programmer overall.

The precise implementations can be nuanced, but Clojure has add-watch , which can do at least the fundamental things (i.e. call a function when a reference's state changes).

🙏 1

Another example is the tap mechanism - an observable singleton dispatching events (emitted with tap>) to observer functions (registered with add-tap and remove-tap).

both mechanisms can be combined, of course.