Fork me on GitHub
#meander
<
2020-05-28
>
aisamu13:05:39

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.

aisamu13:05:14

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}}}

aisamu13:05:45

{} are lists (just to mess with us), _ is one of anything (regex .), ___ is a list of anything or blank (regex .*) :> is a "binding"

noprompt17:05:17

I 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. 👍

eoliphant16:05:00

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 situations

noprompt17:05:39

@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 ".."])

noprompt17:05:08

This yield k/v pairs.

eoliphant17:05:18

ah I see, then just jam those into a map

eoliphant17:05:22

that makes sense

noprompt17:05:51

You can also use this “trick” to do validations e.g. where you search for the errors.

eoliphant17:05:56

thanks. really great stuff by the way.

noprompt17:05:21

Thanks. I appreciate the compliment. 👍

eoliphant17:05:35

stuff like this and specter really take the clojure data-fu to the next level

noprompt17:05:46

It’s a work in progress but I hope its a worthy contribution. 🙂

eoliphant17:05:22

lol, I think it already is, but looking forward to what’s next

noprompt17:05:10

Patience is whats next 😛

noprompt17:05:10

The pandemic really punched my lights out. The lockdown has definitely put some things in to perspective.

noprompt17:05:58

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.

noprompt17:05:41

Moral of the story: I need to take better care of myself.

8
noprompt18:05:43

I had a ton of stuff planned to release this summer but like everything else there’s gonna be delays.

noprompt18:05:36

But hopefully not too much delay.

noprompt18:05:53

I want some better stuff too! 😄

noprompt18:05:51

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).

aisamu18:05:55

Pinging meander folks!

noprompt18:05:08

I have no idea! 🙂

noprompt18:05:48

But, hey, we would love more contribution/help with that. I would love to learn more bytecode stuff.

Jimmy Miller18:05:24

I replied on there.

noprompt22:05:07

One small feature that will show up soon is the ability to turn on/off certain compiler features, etc.

noprompt22:05:57

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.

noprompt22:05:45

If we play our cards right we can enable/try out new things, maybe even eliminate some bottlenecks/fix annoyances quickly.

noprompt22:05:20

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]}] 

noprompt22:05:29

The motivation to turn on/off compiler features is so that we can be sure that the semantics are preserved.

noprompt22:05:07

This was spurred on by a recent bug I discovered in an optimization and that made me paranoid. 🙂

noprompt22:05:33

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. 👍

noprompt22:05:44

Transparency! 🙂

noprompt22:05:35

Also, I think by doing this I can tweak some implementation details in the compiler that might actually be slowing things down.