I saw this on #malli and thought it would be a great fit for rewrite, but the bit of meander-fu I had acquired has unfortunately dissipated π
[:map
[:user map?]
[:profile map?]
[:nested [:map [:x [:tuple {:deleteMe true} string? string?]]]]
[:token [string? {:deleteMe true}]]]
;; meander magic => [:map [:user map?] [:profile map?] [:nested :map]]
I could pull it off with Mathematica (will put on the thread), but I can't seem to translate that to Meander.original =
{"map" ,
{"user", OddQ},
{"profile", EvenQ},
{"nested", {"map", {"x", {"tuple", "DELETE-ME", StringQ, StringQ}}}},
{"token", {StringQ, "DELETE-ME"}}};
ReplaceAll[original, {_, {_, "DELETE-ME", ___}} :> Nothing]
{map,{user,OddQ},{profile,EvenQ},{nested,{map}}}
{}
are lists (just to mess with us),
_
is one of anything (regex .
),
___
is a list of anything or blank (regex .*
)
:>
is a "binding"
hi, is there a way to handle conditions in a single mapping?
; to get something like this
{:foo/a "..."
:foo/b "..."
:foo/optional ".."}
; to
{:a "..."
:b "..."}
; or this if :foo/optional is present
{:a "..."
:b "..."
:optional "..."}
I see that I can do it with conditional matches as arguments to say find
, but that seems like it could get repetitive in certain situationsI think itβd be good to turn something like this into an issue as well. Bringing in things from other established term rewriting systems is definitely a goal here. π
@eoliphant In cases like these, search
is what I use
(m/search {:foo/a "..."
:foo/b "..."
:foo/optional ".."}
{:foo/a (m/pred string? ?value)}
[:a ?value]
{:foo/b (m/pred string? ?value)}
[:b ?value]
{:foo/optional (m/pred string? ?value)}
[:optional ?value])
;; =>
([:a "..."] [:b "..."] [:optional ".."])
This yield k/v pairs.
ah I see, then just jam those into a map
Yah
that makes sense
You can also use this βtrickβ to do validations e.g. where you search for the errors.
thanks. really great stuff by the way.
Thanks. I appreciate the compliment. π
stuff like this and specter really take the clojure data-fu to the next level
Itβs a work in progress but I hope its a worthy contribution. π
lol, I think it already is, but looking forward to whatβs next
Patience is whats next π
The pandemic really punched my lights out. The lockdown has definitely put some things in to perspective.
With my kids home all the time and not being able to hack as much, its given me a chance to take a moment and think about this open source thing.
Moral of the story: I need to take better care of myself.
I had a ton of stuff planned to release this summer but like everything else thereβs gonna be delays.
But hopefully not too much delay.
I want some better stuff too! π
A road map of sorts would be: ensure the epsilon
arm is in good shape, solid, and then release zeta
sometime within the next year (`zeta` is built using epsilon
).
Pinging meander folks!
I have no idea! π
But, hey, we would love more contribution/help with that. I would love to learn more bytecode stuff.
I replied on there.
Thanks!
One small feature that will show up soon is the ability to turn on/off certain compiler features, etc.
The first iteration of this wonβt be noticeable/immediately useful but after the foundation is set we can add support for alternative stuff like namespaced ::as
patterns so that
{:as ?as, :bs ?bs}
will match/build
{:as [1 2 3], :bs [1 2 3]}
or whatever.If we play our cards right we can enable/try out new things, maybe even eliminate some bottlenecks/fix annoyances quickly.
The idea will be that we can set these options via meta on the macro forms
^{::m/as-keyword ::m/as}
(m/match {:as [1], :bs [2 3]}
{:as ?as ::m/as ?it}
[?as ?it])
;; => [[1], {:as [1], :bs [2 3]}]
The motivation to turn on/off compiler features is so that we can be sure that the semantics are preserved.
This was spurred on by a recent bug I discovered in an optimization and that made me paranoid. π
Hopefully this checks some confidence boxes for folks too. I know there was some concern about zeta
being written with epsilon
and epsilon
having bugs. I feel the same concern and its why Iβm doing this. π
Transparency! π
Also, I think by doing this I can tweak some implementation details in the compiler that might actually be slowing things down.