meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
ingesol 2019-12-07T12:37:09.398600Z

Hi! I thought it would be useful to document my meander learning with interactive examples, so I tried to do a KLIPSE post. Didn’t work so just posting the link here as a reproducible case. Is this because of meander being not self-host compatible, or are there other things that I would need to fix? http://ingesolvoll.github.io/posts/2019-12-07-meander-examples/

ingesol 2019-12-07T12:39:41.399800Z

And for reference, it uses the KLIPSE technique of including external source like this

<pre><code class="klipse-cljs nohighlight" data-external-libs="https://raw.githubusercontent.com/noprompt/meander/epsilon/src">   (require '[meander.epsilon :as m]) </code></pre>
And the error that in the end blocks it is “Execution error. ERROR in file https://raw.githubusercontent.com/noprompt/meander/epsilon/src/meander/match/ir/epsilon.cljc: TypeError: Cannot read property ‘call’ of undefined”

jimmy 2019-12-07T16:56:22.404600Z

So I have a self-hosted meander that is working somewhat (incomplete: https://try-meander.now.sh/) It has errors, but they seem fixable. Sadly, klipse uses its own setup that is different from shadow-cljs. I’m honestly not sure what to make of the error message klipse is giving. When I run it I get

ERROR in file <https://raw.githubusercontent.com/noprompt/meander/epsilon/src/meander/match/ir/epsilon.cljc>: TypeError: meander.match.ir.epsilon$macros.body_fn is undefined
Which makes even less sense

dominicm 2019-12-07T18:47:17.404800Z

Is there a way to match on the index of a pattern? e.g. find me a ?x that's in an odd position and also matches some other predicate.

dominicm 2019-12-07T19:08:50.404900Z

I don't understand why this isn't [2 3] :) I think I'm missing something fundamental:

(m/rewrite [1 2 3]
              [1 . !x ...] !x)

noprompt 2019-12-07T19:17:42.406800Z

@dominicm ha! Someone else brought this up recently. No we don’t. But I think it would be useful. I’m not sure what it might look like. Any thoughts?

dominicm 2019-12-07T19:19:30.406900Z

I may have found a way to achieve it :thinking_face:

dominicm 2019-12-07T19:21:08.407Z

No, not quite. I thought some variation on (m/match [1 2 3 4] [!xs !ys ...] [!xs !ys]) might do it.

dominicm 2019-12-07T19:22:09.407100Z

I guess I'm trying to express a memory variable that's scoped to each possible match?

clojuregeek 2019-12-07T19:28:51.409100Z

wondering why the name search is used when you expect many and match when you only want one … wouldn’t match and match-all be more straight forward? search doesnt necessarily read “gonna get a bunch of stuff” where match-all would ? 🙂 .. just curious as I am reading through the code

dominicm 2019-12-07T19:36:08.409200Z

oh, duh. Because I need more .... Long day

dominicm 2019-12-07T19:39:11.409400Z

Hmm. Here's a new one. I want a memory variable, but I want to bound it into a context of some kind, the intention being to unify with another use of a memory variable:

(m/rewrite
    [[1 2 3]
     [:a 2 3]]

    [[?init . !rest ...]
     [?alt-init . !rest ...]]

    [(?init ?alt-init) . !rest ...])
I want the first & second use of !rest to unify.

jimmy 2019-12-07T19:46:04.409500Z

match-all would definitely a good name as well. I think search probably comes from the way it is implemented. With match we are literally just checking if your input matches the pattern. With search, we are looking at your input and searching for ways that things can match.

jimmy 2019-12-07T19:48:47.410Z

@dominicm Here’s one way to accomplish that.

(m/match
  [[1 2 3]
   [:a 2 3]]

  [[?init &amp; ?rest]
   [?alt-init &amp; ?rest]]
  
  (let [!rest ?rest]
    (m/subst
      [(?init ?alt-init) . !rest ...])))

dominicm 2019-12-07T20:10:17.411100Z

Why use match? Why rebind to a memory var?

dominicm 2019-12-07T20:11:50.411300Z

Interestingly, I can't find any docs on &amp;

jimmy 2019-12-07T20:13:00.413200Z

Rewrite is just match + sub. If we are missing docs on & I will definitely add those. It just means match on the rest. Without rebinding I couldn't have used ... Maybe we should consider allowing that for logic variables so that trick is unnecessary? Not sure.

dominicm 2019-12-07T20:13:08.413300Z

Should that be m/let?

jimmy 2019-12-07T20:14:27.415600Z

Nope. I did the clojure let intentionally. That is why I used match and subst directly instead of rewrite. As always there may be a better way I didn't think of.

noprompt 2019-12-07T20:25:13.417800Z

I’m doing chores at the moment! 😅

clojuregeek 2019-12-07T20:27:42.418Z

ok .. 🤷

noprompt 2019-12-07T20:28:28.418600Z

&amp; works on the right side of rewrite rules.

noprompt 2019-12-07T20:28:31.418900Z

(m/rewrite [[1 2 3] [:a 2 3]]
  [[?init-1 &amp; ?rest] [?init-2 &amp; ?rest]]
  [(?init-1 ?init-2) &amp; ?rest])
;; =&gt;
[(1 :a) 2 3]

noprompt 2019-12-07T20:28:43.419100Z

@dominicm☝️

jimmy 2019-12-07T20:29:03.420100Z

Oh yeah. See that was the better way I couldn't think of

clojuregeek 2019-12-07T20:29:05.420300Z

at least this one is documented 🙂

clojuregeek 2019-12-07T20:29:12.420500Z

noprompt 2019-12-07T20:29:21.421Z

I knoooooooow we need to document this!!! Don’t kill us!!! 🤪

clojuregeek 2019-12-07T20:29:46.421700Z

i will submit a PR if i can come with some good ones 🙂

1➕1🙂
noprompt 2019-12-07T20:29:54.421900Z

@clojuregeek Trollin’ eh? 😛

noprompt 2019-12-07T20:30:15.423100Z

@clojuregeek Yah! Go for it. I merge doc patches with almost no hesitation.

clojuregeek 2019-12-07T20:30:24.423500Z

no i was poking at the code this morning and remember looking up what $ was

noprompt 2019-12-07T20:30:40.423800Z

Its jQuery for Clojure. 😉

clojuregeek 2019-12-07T20:31:14.424Z

ok

noprompt 2019-12-07T20:38:29.424500Z

@clojuregeek The docstring for $ should be much longer than that.

jimmy 2019-12-07T20:42:20.425300Z

The docs there are from the doc strings.

dominicm 2019-12-07T21:00:55.425400Z

I'm done with mine for the day. I have 5 gold stars which means I get to play on my computer for a bit... 😅

noprompt 2019-12-07T21:13:14.425900Z

I am noticing that a word or two needs to be said about the substitution side of that one.