Fork me on GitHub
#meander
<
2021-04-20
>
euccastro15:04:10

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

euccastro15:04:41

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

euccastro15:04:28

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

euccastro15:04:59

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

euccastro15:04:18

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?

noprompt16:04:07

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

noprompt16:04:59

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.

euccastro16:04:50

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

noprompt16:04:58

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.

👍 5
noprompt16:04:37

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

noprompt16:04:19

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.

noprompt16:04:11

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.

🎉 17
noprompt16:04:42

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.

noprompt17:04:02

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.

noprompt17:04:29

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