meander 2022-08-28

(s/rewrite 1 2 ?x (m/cata 1))
Syntax error macroexpanding meander.substitute.epsilon/substitute at (/private/var/folders/8r/y2d3thln6s3fyrl_s6vknb440000gn/T/form-init7105795044570115737.clj:1:1).
cata not allowed here
(m/rewrite :a 1 2 ?x (m/cata 1))
=> 2
^^ This is confusing to me 🙂

Is s/rewrite expanding incorrectly?

I think that error is when m/cata is on the left side, top level.

Expansion might be the issue

no big deal, I wouldn't worry about it, just reported it. ¯\(ツ)/¯

one thing I was wondering was whether meander does or can do tail recursion

I was messing with using m/app recur

and it kinda almost does something but complains about the number of args

probably due to function nesting

lol I have no idea what I'm talking about

I was doing some reasonably weird stuff admittedly.

But it seemed to work fine with m/rewrite so that's good 🙂

To answer you question directly:

(macroexpand '(s/rewrite 1 2 ?x (m/cata 1)))
=>
(fn*
 ([x__7086__auto__]
  (meander.match.epsilon/find
   x__7086__auto__
   1
   (meander.substitute.epsilon/substitute 2)
   ?x
   (meander.substitute.epsilon/substitute (m/cata 1))
   _
   meander.strategy.epsilon/*fail*)))
and the other one:
(macroexpand '(m/rewrite :a 1 2 ?x (m/cata 1)))
=>
(let*
 [TARGET__8094 :a]
 (clojure.core/let
  [R__8099
   (clojure.core/letfn
    [(C__8092
      [TARGET__8094]
      (clojure.core/letfn
       [(state__8096 [] (if (clojure.core/= TARGET__8094 1) [2] (state__8097)))
        (state__8097
         []
         (clojure.core/let
          [?x TARGET__8094]
          (try
           [(clojure.core/let
             [R__8093 (C__8092 1)]
             (if
              (meander.match.runtime.epsilon/fail? R__8093)
              (throw meander.substitute.runtime.epsilon/FAIL)
              (clojure.core/nth R__8093 0)))]
           (catch
            clojure.lang.ExceptionInfo
            e__6502__auto__
            (if
             (meander.substitute.runtime.epsilon/fail? e__6502__auto__)
             meander.match.runtime.epsilon/FAIL
             (throw e__6502__auto__))))))]
       (state__8096)))]
    (clojure.core/let
     [R__8098 (C__8092 TARGET__8094)]
     (if
      (meander.match.runtime.epsilon/fail? R__8098)
      meander.match.runtime.epsilon/FAIL
      (clojure.core/let [[R__8095] R__8098] R__8095))))]
  (if (meander.match.runtime.epsilon/fail? R__8099) nil R__8099)))

¯\(ツ)/¯

I think just ignore it for now.