Is <pattern> ..1
the idiomatic way to express a subpattern there may or not be one of?
That would be one or more repeated. Thing + in regex. If you have an example I context I'm sure we could help with the way to express what you are looking for.
Iโm looking for ?
from regex, basically.
there is a way to emulate ?
though itโs not very obviousโฆ consider this pattern:
(m/and [1 2 . !?x ... :a :b] (m/guard (<= (count !?x) 1))
I wish there was a more compact way ๐
!?x
will be a memory variable (array) of either 1 value or empty.
for a more complete example https://github.com/timothypratley/justice/blob/master/src/justice/defn.cljc
Right now there is no direct way to say that. It depends on the context you are in. It is something we definitely have considered. But it is sadly a little complicated. In most cases you can use m/or or you can use multiple patterns to get what you are looking for.
Got it! Thanks.
Iโm a bit confused with how m/search
and m/scan
interact with memory variables.
Firstly, is it okay to use m/search
and m/scan
with memory variables?
Yeah it is perfectly find to use those together. Depending on how you use it, you can get different outcomes. For example here I can find all the subvectors (for lack of a better term) of a vector that contain 1 or more even numbers.
(m/search [1 2 4 5 7 6 8]
(m/scan (m/pred even? !xs) ..1)
!xs)
;; =>
([2] [2 4] [4] [6] [6 8] [8])
If something isnโt okay to use together, we try to tell you that. Like scan cannot be used with match and you will get an error.
Why would this match
(m/match [:d {}]
[:d {}]
:e)
but this not match
(m/match [:d {}]
[:b [(m/or [:f !c] _) ...]]
!c
[:d {}]
:e)
?Getting rid of the m/or
seems to resolve the issue, but I donโt understand why.
I would have expected that adding another clause would have no effect on the subsequent clauses.
That is to say, I thought it tried all the clauses in order?
That honestly seems like a bug to me. I will look into what is going on.
Yeah definitely a bug. Very strange one. Going to see in the time I have if I can track it down and fix it.
Sorry you ran into that.
No worries! Should I file an issue?
I found the problem and have a fix for it. Will push it up and have @noprompt teach me how to make a release so I can stop bothering him to do it ๐ Thanks for offering though
[meander/epsilon "0.0.378"]
@zane Bug is fixed here
I might look up the bugfix because I'm curious.
We take bugs seriously and try to remedy them as quickly as possible. ๐
https://github.com/noprompt/meander/commit/c64d58638f6412efc010215bf80d781e9608e310
I caused the bug before by not thinking clearly about type inference across multiple matches. This code was wrong as soon as I wrote it. So deleting it was the best option.