In consideration of the many suggestions to have a way to do aggregation, zeta
will introduce an operator just for this that will work with mutable variables *m
which currently have little value. Right now this operator is called fold
but may end up having a different name.
fold
has the signature
(fold *mutable-variable <initial-value> <reducing-fn>)
Here’s an example based on a problem someone shared today:
(rewrite [{:time 2} {:time 1} {:time 3} {:time 0}]
(mz/with [%max-time (mz/fold *max-time 0 max)
%min-time (mz/fold *min-time 0 min)]
[{:time (mz/and %max-time %min-time)} ...])
{:max-time *max-time
:min-time *min-time})
;; =>
{:max-time 3
:min-time 0}
fold
can also be on the right side of rewrite
rules which means “unfold” and an unfold function can be registered for this purpose. For example, the unfold of min and max are dec
and inc
respectively starting from the initial-value
or bound value of the mutable variable.
I may have mentioned it previously but you’ll also be able to generate data from patterns as well:
((gen [[:id (mz/fold *id 100 max)]
[:status (mz/or "pending" "delivered")] ...]) {})
;; =>
([]
[[:id 101] [:status "pending"]]
[[:id 101] [:status "pending"]
[:id 102] [:status "pending"]]
[[:id 101] [:status "delivered"]]
[[:id 101] [:status "pending"]
[:id 102] [:status "pending"]
[:id 103] [:status "pending"]]
,,,)
(Ignore the details for now.) 🙂I may have also mentioned that the quality of the new runtime and code generator is much better than of any previous version of the library. The core parts of the parser and compiler are being written with epsilon
and compiled to Clojure code which uses the new runtime. At some point it’ll break with epsilon
entirely and zeta
will bootstrap itself.
At the current rate of progress I estimate — but won’t promise — a stable release of zeta
some time in June or July.
If I get to a point of confidence with the runtime code, I think I can also make a “programmable” API available. Of course, it won’t be as fast as the macro flavor but the option will be available (hopefully).