This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-31
Channels
- # announcements (6)
- # babashka (40)
- # beginners (6)
- # calva (1)
- # cider (1)
- # clerk (43)
- # clj-kondo (3)
- # clojure (93)
- # clojure-denver (8)
- # clojure-europe (52)
- # clojure-norway (20)
- # clojure-sweden (7)
- # community-development (5)
- # datascript (15)
- # datomic (30)
- # emacs (24)
- # events (15)
- # fulcro (23)
- # graalvm (12)
- # gratitude (1)
- # helix (4)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (26)
- # lambdaisland (3)
- # lsp (6)
- # matcher-combinators (2)
- # matrix (5)
- # meander (39)
- # nrepl (4)
- # nyc (1)
- # off-topic (5)
- # portal (73)
- # practicalli (1)
- # re-frame (2)
- # reitit (22)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (5)
- # sql (17)
- # testing (1)
- # tools-deps (15)
The https://cljdoc.org/d/meander/epsilon/0.0.650 in the README
appears to be broken?
The https://repo.clojars.org/meander/epsilon/0.0.650/epsilon-0.0.650.pom does not point back to meander sources on GitHub.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation=" ">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>meander</groupId>
<artifactId>epsilon</artifactId>
<version>0.0.650</version>
<name>epsilon</name>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.10.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
<repositories>
<repository>
<id>clojars</id>
<url> </url>
</repository>
</repositories>
</project>
Cljdoc https://github.com/cljdoc/cljdoc/blob/master/doc/userguide/for-library-authors.adoc#git-sources`<scm>`https://github.com/cljdoc/cljdoc/blob/master/doc/userguide/for-library-authors.adoc#git-sources.
Older versions of meander published to clojars do have some <scm>
info so, the build process probably changed.
And meander does have a doc/cljdoc.edn
to there has been historical interest in cljdoc.
Thanks for looking into it, @UE21H2HHD!
Oh @zane, I think I maybe misunderstood, I thought you were noting that the articles did not import on cljdoc, and that's what I looked into.
I was just trying to clarify what was probably already clear from the screenshot: That the link successfully takes you to a webpage, but that the webpage has problems.
Oh https://github.com/noprompt/meander/issues/236, I'll add some details.
@zane, I added the rhttps://github.com/noprompt/meander/issues/236#issuecomment-1572194270.
I’m struggling with meander’s documentation for what (to me) seems to be a simple transformation. I want to transform nested repeated content along with the containing content. I can’t figure it out. Here’s an example:
{:a [{:b 1 :x 12} {:b 2 :y 13}]}
needs to become:
{:A [{:B 1 :x 12} {:B 2 :y 13}]}
It’s the changes to the N contained maps that confounds me. I can do it with a “manual” mapping of meander/match
over the value at the :a
key, but that seems to break the promise of meander’s declarative approach.
Thanks in advance, and my apologies if I’ve missed something in the docs. Memory variables seem like a crucial ingredient, but I can’t see a way to “unify” the elements of each map “positionally” in the output expression to preserve the arity of the input value.You want to rewrite everything in the top level and also everything one level down? I might just thread through two rewrites.
Yes, that’s correct. Can you explain what you mean by “thread through two rewrites?” The cleanest method I can come up with involves mapping over the repeated key’s value with a secondary meander/match
call. But that just seems wrong. Here’s the rough shape:
(meander/match input
{:a [!nested ...]}
{:A (mapv #(meander/match %
{:b ?b :x ?x :y ?y}
{:B ?b :x ?x :y ?y})))
(the :x
and :y
keys are not particularly relevant to this problem and their nil values in the result doesn’t match exactly the example I gave above -ignore it)Hmm. What I had in mind didn't work when I actually tried to write code. I was thinking thread-first ->
through m/rewrite
for :a
to :A
and then again m/rewrite
to turn {:A [{:b ...
into {:A [{:B ...
This probably isn't what you want but I still don't understand what you want.
(m/rewrite {:a [{:b 1 :x 3}
{:b 2 :y 4}]}
{:a [!a ...] & ?rest}
{:A [(m/cata !a) ...] & ?rest}
{:b ?b & ?rest}
{:B ?b & ?rest})
m/cata
recurses on each thing. If there's another :a
there then it'll get matched. that's probably not what you want.
Is this the kind of thing you are looking for?
(def input {:a [{:b 1 :x 12} {:b 2 :y 13}]})
(m/rewrite input
{:a [{:b !bs & !xs} ...]}
{:A [{:B !bs & !xs} ...]})
;; =>
;; {:A [{:x 12, :B 1} {:y 13, :B 2}]}
In words, I want to transform a map containing a sequence of maps at some key. I see how to transform a map with a sequence at some key, but if the sequence is composed of maps then I see no way to modify the child maps without a second invocation of meander. It seems weird that nested data structures can’t be “described” sufficiently to allow this. Again, here is the shape of the input:
{:a [{:b 1} {:b 2}]}
The desired output requires transformation of the outer map and the inner maps. So something like this:
{:A [{:B 1} {:B 2}]}
The keys at each level are arbitrary and could be duplicated such that nesting context would be essential, but my data doesn’t have that twist.@U5K8NTHEZ, I need to study your solution -it looks very close to what I need.
Unfortunately, I think the problem with that solution is that it treats the subsequence as a memorization (= memory variable) and AFAICT there is no means to correlate memory variables. A slightly extended example shows how that approach will come up short:
{:a [{:b 1 :c 3} {:b 2 :c 4}]}
the desired output requires that the inner maps remain correlated entities:
{:A [{:B 1 :C 2} {:B 2 :C 4}]}
With memory variables, I don’t think it is possible to retain the correlation of 1
and 3
in the first inner map (and similarly for 2
and 4
in the second inner map).
My expectations might be unreasonable: I was expecting equivalent transformation power on nested repeated data as on the top-level data. Perhaps invoking meander twice is the best option.
(m/rewrite {:a [{:b 1 :c 3} {:b 2 :c 4}]}
{:a [{:b !b :c !c & !xs} ..!n] & ?rest}
{:A [{:B !b :C !c & !xs} ..!n] & ?rest})
;; {:A [{:B 1, :C 3} {:B 2, :C 4}]}
I'm confused on the output.
{:b 1 :c 3}
;; turns into
{:B 1 :C 2}
Was that a typo?Assuming it is a typo
(m/rewrite input
{:a [{:b !bs :c !cs & !xs} ...]}
{:A [{:B !bs :C !cs & !xs} ...]})
Seems to work on that inputSo yeah. That seems to work. There are ways to correlate memory variables more specifically but I don’t see the need for that here. So I must be missing something.
So that ^ shows that the memory variables are being “consumed” in parallel and maintain the correlation of the map entities.
Yeah you can do some fancier things with different repeat operators. But in general they do one value for each repeat. So for the same length things they should be fine.
@U5K8NTHEZ and @UPD88PGNT, thanks for your help with this. I’ve got additional requirement that I fear may break the solutions you have proposed… I need each of the subordinate output maps to include the index of the subordinate input maps. So using @UPD88PGNT’s example from above:
(m/rewrite {:a [{:b 1 :c 3} {:b 2 :c 4}]}
{:a [{:b !b :c !c & !xs} ..!n] & ?rest}
{:A [{:B !b :C !c & !xs} ..!n] & ?rest})
;; {:A [{:B 1, :C 3 :index 1} {:B 2, :C 4 :index 2}]}
Note the addition of the :index
key in the desired output. Is this possible?
Similarly to how the keys
and vals
functions in Clojure core commit to returning the keys and values in the same order, I’m wondering if your collective opinion is that the “correlation” of the memory variables is intentional (by the authors of meander) or if it is “luck” -I’m hesitant to invest a lot in this approach without some confidence that it is intentional.Not at my computer. I’ll have to think about index. But I can confirm for sure that the “correlation” isn’t accidental. The way memory variables work is just conceptually push and pop into a vector.
For index, I am sure there is some other way. But this was what I first came up with for doing it.
(m/rewrite {:a (map-indexed vector [{:b 1 :c 3} {:b 2 :c 4}])}
{:a ([!index {:b !b :c !c & !xs}] ...) & ?rest}
{:A [{:B !b :C !c :index (m/app inc !index) & !xs} ...] & ?rest})
Maybe not the most elegant approach ever. But as far as I know we don't have any way to get the index of where you are in a vector. Maybe some cata magic? But personally, I think it is totally fine to do some preprocessing. So ultimately, I'd just do something like
defn add-index [coll]
(into []
(map-indexed
(fn [i x]
(assoc x :index (inc i))))
coll))
(m/rewrite {:a (add-index [{:b 1 :c 3} {:b 2 :c 4}])}
{:a [{:b !b :c !c & !xs} ...] & ?rest}
{:A [{:B !b :C !c & !xs} ...] & ?rest})