meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
aisamu 2020-01-06T12:20:07.282700Z

NP, thanks! Would love to know what the correct result is, though!

aisamu 2020-01-06T12:28:07.283Z

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 :)

jimmy 2020-01-06T15:06:58.283300Z

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🎉
noprompt 2020-01-06T19:51:32.283600Z

It should be ([:a] [:b]).

noprompt 2020-01-06T19:52:25.283800Z

Oh, sorry, no, it should just be (:a :b).

noprompt 2020-01-06T19:52:44.284Z

So the #fail there is the only problem.

1👌
noprompt 2020-01-06T19:57:11.284900Z

[meander/epsilon "0.0.357"]
• Fixes strategy version of rewrites to avoid returning #meander.epsilon/fail in its result set.

noprompt 2020-01-06T19:58:37.285400Z

Fixed

1🎉
timothypratley 2020-01-06T20:39:23.285800Z

I for one would like to hear more about Longest.

timothypratley 2020-01-06T20:41:19.286Z

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.

timothypratley 2020-01-06T20:43:29.286200Z

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)

timothypratley 2020-01-06T20:52:18.286400Z

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)

timothypratley 2020-01-06T20:57:52.286900Z

it seems one way to look at this is that grouping would solve it, and & provides grouping.

1
jimmy 2020-01-06T21:20:59.287600Z

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👀
jimmy 2020-01-06T21:22:31.287900Z

Honestly don't know why I didn't think of this before. It isn't too bad at all.

timothypratley 2020-01-06T21:24:47.288100Z

Oh nice!!!! 🙂