meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
euccastro 2021-04-20T15:10:10.133200Z

suppose I have a map like

{:id 1
   :label "the gizmo label"
   :type.id 5
   :type.label "the type label"
   :owner.id 8
   :owner.name "John Shutt"}

euccastro 2021-04-20T15:10:41.133600Z

and I want to convert it to this format:

{:id 1
   :label "the gizmo label"
   :type {:id 5 :label "the type label"}
   :owner {:id 8 :name "John Shutt"}}

euccastro 2021-04-20T15:11:28.134400Z

(i.e., a dot in the keys causes nesting, and I don't know any key names statically)

euccastro 2021-04-20T15:11:59.134900Z

I have a few questions. first one: how do you accumulate into a map?

euccastro 2021-04-20T15:49:18.136200Z

in plain Clojure this transformation would be:

(defn nest-dots
  [m]
  (reduce-kv
   (fn [m' k v]
     (assoc-in m'
               (map keyword (string/split (name k) #"\."))
               v))
   {}
   m))
(with possibly nested dots, which is not really a requirement) do you think there's a more understandable/transparent meander implementation?

noprompt 2021-04-20T16:14:07.136600Z

(me/rewrite m
  {:id ?id
   :label ?label
   :type.id ?type-id
   :type.label ?type-label
   :owner.id ?owner-id
   :owner.name ?owner-name}
  {:id ?id
   :label ?label
   :type {:id ?type-id
          :label ?type-label}
   :owner {:id ?owner-id
           :name ?owner-name}})

noprompt 2021-04-20T16:25:59.138700Z

It is possible to do something more generic like splitting on the dot etc. but the transformation language hasn’t matured enough to accommodate a clean way to do this.

euccastro 2021-04-20T16:27:50.141Z

thanks! yes, my use case would be definitely about splitting on the dot, since the transformation would have to handle keys not known statically

noprompt 2021-04-20T16:27:58.141200Z

Accumulation/Aggregation is something that is planned for the next version of the library which I’ve been working on and hope to release sometime this year. The approach I’ve decided to take for the next version is completely different from the previous versions and is a complete rewrite of the library. Anyway, each of the variable types present in the current version can be seen as a type of memory with semantics for storage and retrieval. The plan is turn this observation into support for user defined types of variables.

👍 2
noprompt 2021-04-20T16:28:37.142Z

If the number dotted keys you have is small and known, I would recommend to simply stick them in the pattern match.

noprompt 2021-04-20T16:32:19.143900Z

In general, I often recommend this approach even if you’re not using Meander because it is obvious and almost always going to be faster.

noprompt 2021-04-20T16:56:11.153900Z

To give folks a brief update on where things are at with zeta most of my time is still being split between 1. compilation, 2. testing, and 3. parsing. Compilation and testing are occupying the most time because, well, compilation is a faceted problem. At the moment, compilation speed has been my focus. Originally, the plan was, for compilation, to have a three step process: build the intermediate representation, optimize it, then turn it in to Clojure. Even though I was able to generate good code this way, the performance was poor due to the size of the trees being optimized. Now what I am doing is optimizing as the tree as it is being constructed to avoid this problem.

🎉 6
noprompt 2021-04-20T16:58:42.155800Z

When I get the time later this year, I hope to write down a detailed explanation of how the internals are designed with the hope of being able to get more help from the community.

noprompt 2021-04-20T17:00:02.157100Z

Once I’m confident that zeta meets the mark, I really want to starting spending more of my time using it rather than working on it.

noprompt 2021-04-20T17:00:29.157600Z

I’ve long wanted to get back into tinkering with L-Systems and learning more about algorithmic botony.