NP, thanks! Would love to know what the correct result is, though!
Thanks! It's still unclear how I'd approach that, though. If you already have the final solution, please don't worry about giving me spoilers :)
There is probably a more succinct way, but here is one example.
(def divide-out-zeros
(r/pipe
(r/rewrite ?xs [?xs [[]]])
(r/until =
(r/rewrite
[[] ?acc] ?acc
[[0 & ?xs] [!acc ...]] [?xs [!acc ... . []]]
[[?x & ?xs] [!acc ... . [!last ...]]] [?xs [!acc ... . [!last ... . ?x]]]))))
(divide-out-zeros [1 2 3 0 4 5 6 0 7 8 0 9])
1🎉It should be ([:a] [:b])
.
Oh, sorry, no, it should just be (:a :b)
.
So the #fail
there is the only problem.
[meander/epsilon "0.0.357"]
• Fixes strategy version of rewrites
to avoid returning #meander.epsilon/fail
in its result set.Fixed
1🎉I for one would like to hear more about Longest.
Seems like it would be nice to define the break token and non-break using with
… &
can’t appear at the start currently but tere is a proposal to allow that… maybe :as
does not bind the vector like I hoped.
oh this works for the last bit only:
(m/find [1 2 3 0 4 5 6 0 7 8 0 9]
[ ;;& [(pred (complement zero?)) ... :as !x]
_ ...
(m/pred zero?) ...
& [(m/pred (complement zero?)) ... :as !x]]
!x)
I think I’d like to be able to write:
(m/match [1 2 3 0 4 5 6 0 7 8 0 9]
(m/with [%break% (pred zero?)
%thing% (m/not %break%)]
[(m/group (m/group %thing% ... :as !x) . %break% ...) ...])
!x)
(doesn’t work)
or
(m/match [1 2 3 0 4 5 6 0 7 8 0 9]
(m/with [%break% (pred zero?)
%thing% (m/not %break%)]
[& [& [%thing% ... :as !x] . %break% ...] ...])
!x)
(almost but not quite)it seems one way to look at this is that grouping would solve it, and &
provides grouping.
Figured out a solution with with
(m/rewrite [1 2 3 0 4 5 6 0 7 8 0 9]
(m/with [%split (m/or [!xs ..!n 0 & %split]
[!xs ..!n])]
%split)
[[!xs ..!n] ...])
1👀Honestly don't know why I didn't think of this before. It isn't too bad at all.
Oh nice!!!! 🙂