meander

xiongtx 2023-08-29T20:02:27.255309Z

Is there a way to search non-constant subsequences? E.g. the following should return [1 2] [7 8]

(m/search [1 2 4 5 7 8]
  [(m/pred odd? ?x) (m/pred even? ?y) ...] [?x ?y])
But instead throws:
Zero or more patterns may not have references to unbound logic variables.
   {:unbound #{?x ?y},
    :syntax-trace
    [((m/pred odd? ?x) (m/pred even? ?y) ...)
     [(m/pred odd? ?x) (m/pred even? ?y) ...]]}

xiongtx 2023-08-30T16:42:12.050539Z

Ah, okay, I didn’t know scan worked w/ multiple args!

Jimmy Miller 2023-08-29T20:16:09.236569Z

You want scan.

(m/search [1 2 4 5 7 8]
  (m/scan (m/pred odd? ?x) (m/pred even? ?y))
  [?x ?y])
Which is basically sugar over
(m/search [1 2 4 5 7 8]
  [_ ... (m/pred odd? ?x) (m/pred even? ?y) . _ ...]
  [?x ?y])