meander

Stephan Renatus 2024-12-30T19:14:34.930339Z

😳 I feel like I’m missing something basic wrt vectors — I’m trying to use bottom-up for rewriting using meander.strategy.epsilon, and it works quite well and nicely, except for that one case (code in thread).

Stephan Renatus 2024-12-30T19:14:41.008539Z

(ns mwe
  (:require [meander.strategy.epsilon :as r])

(def rewrite
  (r/until =
    (r/bottom-up
     (r/attempt
      (r/trace
       (r/rewrite
         [{:terms !ands} ...] {:ands [!ands ...]}
         ;; TODO: multiple AND's are OR'ed together
        ))))))

(def r1
  (rewrite [[{:terms :p}, {:terms :q}]]))
;; should be: `[:or [:and :p :q]]`

(def r2
  (rewrite [[{:terms :p}], [{:terms :r}]]))
;; should be: `[:or [:and :p] [:and :r]]
`

Stephan Renatus 2024-12-30T19:16:39.344909Z

the result for r1 is with the current code (which is lacking all support for adding :or)

{:ands [nil]}
trace yields this, which puzzles me:
{:id t_55682, :in [{:terms :p} {:terms :q}]}
{:id t_55682, :out {:ands [:p :q]}}
{:id t_55682, :in [{:ands [:p :q]}]}
{:id t_55682, :out {:ands [nil]}}
the first rewrite perfectly covers my intention, but the second hoses it all.

Stephan Renatus 2024-12-30T19:16:56.742269Z

similarly r2,

{:ands [nil nil]}

Stephan Renatus 2024-12-30T19:30:07.272209Z

I’m aware that I probably don’t need the strategy apparatus for this simple example; but there is more to rewrite that I’ve left off the MWE — it’s also not been giving me something unexpected on that 🙃