Fork me on GitHub
#meander
<
2021-01-20
>
dgr00:01:49

Am I going insane or is this not acting right. (Sorry for the large splat of code with probably horrible indentation.) xyz.core> x {:class :org.commonmark.node.Document, :children ({:class :org.commonmark.ext.front.matter.YamlFrontMatterBlock, :children ({:children (), :key "Title", :values ["Meta title"], :class :org.commonmark.ext.front.matter.YamlFrontMatterNode})})} xyz.core> (meander/find x {:class :org.commonmark.node.Document :children (_ ... {:class :org.commonmark.ext.front.matter.YamlFrontMatterBlock :children (_ ... . {:class :org.commonmark.ext.front.matter.YamlFrontMatterNode :key "Title" :values [!title ...] } . _ ...)} . _ ...)} [:html [:head [:title !title]]]) nil xyz.core> (meander/find x {:class :org.commonmark.node.Document :children (_ ... {:class :org.commonmark.ext.front.matter.YamlFrontMatterBlock :children (_ ... . {:class :org.commonmark.ext.front.matter.YamlFrontMatterNode :key "Title" :values !title } . _ ...)} . _ ...)} [:html [:head [:title !title]]]) [:html [:head [:title [["Meta title"]]]]]

dgr00:01:14

Look at the :values piece of the pattern. For some reason, [!title …] doesn’t match a vector of strings and pick up each string, but !title does match the whole vector. Is that right? What am I missing?

dgr00:01:53

But this works as expected in the small: xyz.core> (meander/find {:values ["Meta title"]} {:values [!title ...]} !title) ["Meta title"]

dgr00:01:38

Literally, the only difference between the first two cases, above, is the :values [!title …] vs. :values !title.

noprompt01:01:23

Taking a look

noprompt01:01:10

Hmm… I’m curious that you get nil because when I tried this at the REPL I get

(let [x '{:class :org.commonmark.node.Document,
          :children
          ({:class :org.commonmark.ext.front.matter.YamlFrontMatterBlock,
            :children
            ({:children (),
              :key "Title",
              :values ["Meta title"],
              :class :org.commonmark.ext.front.matter.YamlFrontMatterNode})})}]
  (me/find x
    {:class :org.commonmark.node.Document
     :children (_ ... {:class :org.commonmark.ext.front.matter.YamlFrontMatterBlock
                       :children (_ ... . {:class :org.commonmark.ext.front.matter.YamlFrontMatterNode
                                           :key "Title"
                                           :values [!title ...]}
                                    . _ ...)}
                  . _ ...)}
    [:html [:head [:title !title]]]))
;; =>
[:html [:head [:title ["Meta title"]]]]

dgr01:01:07

Yea, I don’t get it either.

Jimmy Miller01:01:23

Is it actually a vector? Or some other type?

😂 3
noprompt01:01:26

So something that could also be going on here is the the value at :values is not a vector?

dgr01:01:31

OK, that works as expected in my REPL, too. I just cut/pasted your text

noprompt01:01:43

(I’m laughing because Jimmy and I have the tendency to simulreply with pretty much the same answers/suspicions.)

noprompt01:01:59

I’m gonna let him type. 🙂

Jimmy Miller01:01:10

Maybe put in an (m/app type !titles) and see.

dgr01:01:10

Ah. Nope, it’s a java.util.ArrayList

dgr01:01:21

But it prints as a vector. Grrrrr…

noprompt01:01:27

You could use m/seqable there.

noprompt01:01:35

Yeah. It is very annoying the printer does that.

dgr01:01:42

OK, so this is a key thing for the documentation.

dgr01:01:56

You still need to get back to me about m/seqable and whether we’re documenting it or not. 🙂

noprompt01:01:35

Ah, yeah, sorry I’ve been just busy. Maybe just hit me/the channel with question about it daily or something?

noprompt01:01:43

But yes, m/seqable should have a docstring.

dgr01:01:58

What does it do?

noprompt01:01:20

Or be documented. Essentially it matches the any seqable? thing with the remaining arguments being the same as those you would stick between [] or ().

noprompt01:01:04

Example

(m/or [1 2 3 . !x !y ...] (1 2 3 . !x !y ...))
;;
(m/seqable 1 2 3 . !x !y ...)

dgr01:01:21

Both. It needs a docstring for docs at the REPL. But also it needs more expansive coverage in the manual.

dgr01:01:45

OK, gotcha.

noprompt01:01:27

Cool. Just turn my gibberish into something that makes sense to the general population. 😛

dgr01:01:38

Alright, I get it.

dgr01:01:46

This is actually good, exploring some of the corner cases.

dgr01:01:09

I just used m/seqable and it worked great.

dgr01:01:13

I’ve had a similar issue before, using [] in the pattern when I was matching a seq/list, and didn’t realize. It’s definitely one of those fine points.

noprompt01:01:58

It’s the big difference in philosophy from, say, core.match.

noprompt01:01:26

I never liked [x y z :seq] or whatever the grossness was.

dgr01:01:11

Yea, I’m OK with how it works in Meander. Just need to get it documented so that it doesn’t trip up others.

dgr01:01:35

I was pulling my hair out for about 45 minutes before I posted here.

noprompt01:01:42

I do think we’ve been up front about that in particular. That () means seq? [] means vector? etc.

noprompt01:01:03

Ah, bummer! 😞

dgr01:01:52

Yea, no biggie. It’s just a key point that needs to be hammered home.

dgr01:01:09

I’ll make sure it receives some coverage in the manual.

noprompt01:01:48

Well, definitely yelp for help next time and keep your hair. 🙂

dgr01:01:07

Also, this wasn’t Meander’s issue. It’s really an issue with the Clojure printer sort of glossing over the difference between vectors and Clojure arrays.

noprompt01:01:25

If it something definitely seems like it should work and it doesn’t it’s either a bug or something else is going on.

noprompt01:01:41

Yeah. I had this problem dealing with XML stuff before.

dgr01:01:32

@jimmy gets the award for the day.

noprompt01:01:58

He’s an award winning guy. 😄

dgr01:01:26

He beat you by 3 seconds.

noprompt01:01:45

And he did teach me a new trick today. I would have lol done it by hand in Clojure. Pretty nifty trick.

noprompt01:01:59

I gotta get up and start making dinner. BBL

dgr01:01:27

Yea, exactly. I was starting to write it by hand in Clojure with multimethods, which would have been fine, but I say, “Wait a second, Meander rocks at term rewriting. I should use that! And it’ll help me with my Meander fu.” And then I spent a whole bunch of time messing with it and trying to get it to work. Doh!