Fork me on GitHub
#specter
<
2018-06-08
>
sophiago21:06:20

@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.

nathanmarz21:06:24

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

sophiago21:06:27

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

nathanmarz21:06:40

so stop navigation at any map?

nathanmarz21:06:55

or stop navigation at maps with a :locals key?

sophiago21:06:00

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"}

sophiago21:06:39

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

nathanmarz21:06:12

ok, so basically don't recurse into :locals

sophiago21:06:48

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

nathanmarz21:06:32

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

sophiago21:06:06

Oh, I did not try something like that

sophiago21:06:12

Let me give it a test

nathanmarz21:06:39

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

sophiago21:06:16

That looks more like what I was trying

sophiago21:06:16

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

sophiago21:06:34

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

sophiago21:06:27

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

nathanmarz23:06:54

that's not what eachnav is for

nathanmarz23:06:37

@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]
               )))

sophiago23:06:40

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.

sophiago23:06:57

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.