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/
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”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 senseIs 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.
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)
@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?
I may have found a way to achieve it :thinking_face:
No, not quite. I thought some variation on (m/match [1 2 3 4] [!xs !ys ...] [!xs !ys])
might do it.
I guess I'm trying to express a memory variable that's scoped to each possible match?
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
oh, duh. Because I need more ...
. Long day
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.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.
@dominicm Here’s one way to accomplish that.
(m/match
[[1 2 3]
[:a 2 3]]
[[?init & ?rest]
[?alt-init & ?rest]]
(let [!rest ?rest]
(m/subst
[(?init ?alt-init) . !rest ...])))
Why use match? Why rebind to a memory var?
Interestingly, I can't find any docs on &
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.
Should that be m/let
?
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.
I’m doing chores at the moment! 😅
ok .. 🤷
&
works on the right side of rewrite rules.
(m/rewrite [[1 2 3] [:a 2 3]]
[[?init-1 & ?rest] [?init-2 & ?rest]]
[(?init-1 ?init-2) & ?rest])
;; =>
[(1 :a) 2 3]
Oh yeah. See that was the better way I couldn't think of
at least this one is documented 🙂
I knoooooooow we need to document this!!! Don’t kill us!!! 🤪
i will submit a PR if i can come with some good ones 🙂
@clojuregeek Trollin’ eh? 😛
@clojuregeek Yah! Go for it. I merge doc patches with almost no hesitation.
no i was poking at the code this morning and remember looking up what $ was
Its jQuery for Clojure. 😉
ok
@clojuregeek The docstring for $
should be much longer than that.
https://cljdoc.org/d/meander/epsilon/0.0.314/api/meander.epsilon
The docs there are from the doc strings.
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... 😅
I am noticing that a word or two needs to be said about the substitution side of that one.