specter

Latest version: 1.1.3
sophiago 2018-06-08T21:05:20.000463Z

@nathanmarz sorry, one more thing I'm stuck on with the navigators above: I'd like the macros that call them to stop at any keys in not-selected?, :locals in this example, rather than just skipping them and navigating deeper. It would seem I just need to move the not-selected? navigators into recursive-path so navigation stops there and setval will only apply the other predicates to elements above it, but that doesn't seem to be working for me, even using separate macros.

nathanmarz 2018-06-08T21:16:24.000102Z

@sophiago you want it to stop navigation at map values whose key is not :locals?

sophiago 2018-06-08T21:17:27.000389Z

The opposite. Stop recursive navigation into the value of that key.

nathanmarz 2018-06-08T21:17:40.000275Z

so stop navigation at any map?

nathanmarz 2018-06-08T21:17:55.000039Z

or stop navigation at maps with a :locals key?

sophiago 2018-06-08T21:20:00.000427Z

So if I have {:foo "bar" :env [{:locals "baz"} {:locals {:baz "qux"}}]} I can use a macro like setval above and not have it delete {:baz "qux"}

sophiago 2018-06-08T21:20:39.000017Z

I've been playing with it and it seems to come down to how I compose predicates in recursive paths

nathanmarz 2018-06-08T21:21:12.000536Z

ok, so basically don't recurse into :locals

sophiago 2018-06-08T21:21:32.000379Z

Yes

sophiago 2018-06-08T21:21:48.000185Z

And more generally, I just want to decouple the recursion from the predicates I'm composing

nathanmarz 2018-06-08T21:23:32.000086Z

(def maps-with-key-stop
  (recursive-path [k] p
    (cond-path map? (if-path (must k)
                      STAY
                      (stay-then-continue MAP-VALS p))
               coll? (compact ALL p)
               )))

(setval
  [(maps-with-key-stop :locals)
   ALL
   (not-selected? FIRST (pred= :locals))
   LAST
   (complement coll?)]
  NONE
  data)

sophiago 2018-06-08T21:24:06.000224Z

Oh, I did not try something like that

sophiago 2018-06-08T21:24:12.000403Z

Let me give it a test

nathanmarz 2018-06-08T21:25:39.000417Z

actually you probably want

(def maps-with-key-stop
  (recursive-path [k] p
    (cond-path map? (stay-then-continue
                      ALL
                      (not-selected? FIRST (pred= k))
                      LAST
                      p)
               coll? (compact ALL p)
               )))

sophiago 2018-06-08T21:26:16.000157Z

That looks more like what I was trying

sophiago 2018-06-08T21:29:16.000135Z

I think I actually want this:

(def maps-with-key-stop
  (recursive-path [k] p
    (cond-path map? (stay-then-continue
                      ALL
                      (not-selected? FIRST (pred= k))
                      ALL
                      p)
               coll? [ALL p])))

sophiago 2018-06-08T21:33:34.000257Z

Except I'm trying to get the k to be a collection and apply isn't giving the same results

sophiago 2018-06-08T21:35:27.000283Z

Oh, that's what eachnav is for, right?

nathanmarz 2018-06-08T23:04:54.000019Z

that's not what eachnav is for

nathanmarz 2018-06-08T23:05:37.000056Z

@sophiago I think you want:

(def maps-with-key-stop
  (recursive-path [kset] p
    (cond-path map? (stay-then-continue
                      ALL
                      (not-selected? FIRST (pred kset))
                      LAST
                      p)
               coll? [ALL p]
               )))

sophiago 2018-06-08T23:12:40.000236Z

Thanks, that works! Just a bit more verbose when I call it. I still have the first issue where it doesn't seem to be recursing inside other colls, though.

sophiago 2018-06-08T23:14:57.000287Z

And I have to delete the extra predicate argument from the first cond or none of these have worked. That seems to make sense to me: I don't actually want (complement coll?) added to the path if the key does match.