@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.
@sophiago you want it to stop navigation at map values whose key is not :locals
?
The opposite. Stop recursive navigation into the value of that key.
so stop navigation at any map?
or stop navigation at maps with a :locals
key?
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"}
I've been playing with it and it seems to come down to how I compose predicates in recursive paths
ok, so basically don't recurse into :locals
Yes
And more generally, I just want to decouple the recursion from the predicates I'm composing
(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)
Oh, I did not try something like that
Let me give it a test
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)
)))
That looks more like what I was trying
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])))
Except I'm trying to get the k
to be a collection and apply
isn't giving the same results
Oh, that's what eachnav
is for, right?
that's not what eachnav
is for
@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]
)))
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.
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.