meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
dgr 2021-01-20T00:45:49.002600Z

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

dgr 2021-01-20T00:47:14.003100Z

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?

dgr 2021-01-20T00:49:53.003500Z

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

dgr 2021-01-20T00:51:38.003800Z

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

noprompt 2021-01-20T01:28:23.004Z

Taking a look

noprompt 2021-01-20T01:36:10.004600Z

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

dgr 2021-01-20T01:37:07.004800Z

Yea, I don’t get it either.

jimmy 2021-01-20T01:38:23.006100Z

Is it actually a vector? Or some other type?

😂 1
noprompt 2021-01-20T01:38:26.006200Z

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

noprompt 2021-01-20T01:38:30.006500Z

Hahah

dgr 2021-01-20T01:38:31.006600Z

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

noprompt 2021-01-20T01:39:43.008600Z

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

noprompt 2021-01-20T01:39:59.009Z

I’m gonna let him type. 🙂

jimmy 2021-01-20T01:40:10.009200Z

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

dgr 2021-01-20T01:40:10.009300Z

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

dgr 2021-01-20T01:40:21.009500Z

But it prints as a vector. Grrrrr…

noprompt 2021-01-20T01:40:27.009800Z

You could use m/seqable there.

noprompt 2021-01-20T01:40:35.010200Z

Yeah. It is very annoying the printer does that.

dgr 2021-01-20T01:40:42.010300Z

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

dgr 2021-01-20T01:40:56.010600Z

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

noprompt 2021-01-20T01:41:35.011400Z

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

noprompt 2021-01-20T01:41:43.011700Z

But yes, m/seqable should have a docstring.

dgr 2021-01-20T01:41:58.012100Z

What does it do?

noprompt 2021-01-20T01:42:20.012600Z

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

noprompt 2021-01-20T01:43:04.013500Z

Example

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

dgr 2021-01-20T01:43:21.014Z

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

dgr 2021-01-20T01:43:45.014200Z

OK, gotcha.

noprompt 2021-01-20T01:44:27.015Z

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

dgr 2021-01-20T01:45:15.015200Z

Ha!

dgr 2021-01-20T01:45:38.015500Z

Alright, I get it.

dgr 2021-01-20T01:45:46.015800Z

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

dgr 2021-01-20T01:46:09.016200Z

I just used m/seqable and it worked great.

dgr 2021-01-20T01:47:13.017Z

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.

noprompt 2021-01-20T01:47:58.017800Z

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

noprompt 2021-01-20T01:48:26.018400Z

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

dgr 2021-01-20T01:49:11.019400Z

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

dgr 2021-01-20T01:49:35.020Z

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

noprompt 2021-01-20T01:49:42.020300Z

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

noprompt 2021-01-20T01:50:03.020700Z

Ah, bummer! 😞

dgr 2021-01-20T01:50:52.021500Z

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

dgr 2021-01-20T01:51:09.022100Z

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

noprompt 2021-01-20T01:51:48.022900Z

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

dgr 2021-01-20T01:52:07.023400Z

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.

noprompt 2021-01-20T01:52:25.023800Z

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

noprompt 2021-01-20T01:52:41.024100Z

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

dgr 2021-01-20T01:53:32.024700Z

@jimmy gets the award for the day.

noprompt 2021-01-20T01:53:58.025200Z

He’s an award winning guy. 😄

dgr 2021-01-20T01:54:26.025400Z

He beat you by 3 seconds.

noprompt 2021-01-20T01:54:45.025800Z

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

noprompt 2021-01-20T01:55:59.026400Z

I gotta get up and start making dinner. BBL

dgr 2021-01-20T01:56:27.026600Z

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!