Fork me on GitHub
#specter
<
2018-05-23
>
sophiago00:05:21

@nathanmarz ironically enough I needed to also write a version of the macro I was struggling with over the weekend that does just stack the lambda bindings at the top of the AST and replaces all instances of corresponding locals. I did this as before by calling setval from inside transform, which I get the sense is not an ideal way to use Specter, but don't fully understand how you rewrote it to use transformed inside the navigator.

nathanmarz02:05:19

@sophiago it'll be easier to understand the navigators if you play with them on toy examples

sophiago02:05:05

True. I tell myself I'm testing these on the simplest functions, but they're still macros doing fairly heavy source transformation. It seems clear the issue here is that I'm trying to apply transformed directly to a symbol, and only the first one that matches as well, rather than in example you gave where it's one level up from the node in a zipper.

sophiago02:05:44

I suppose it's just the combination of learning what's essentially a whole DSL and wanting to use it immediately given how well it fits so many of my problems. For example, it would seem calling setval from inside transform as in the first example shouldn't cause a significant hit in perf, but I'd have to actually look at your macros or at least reread the wiki page about caching to make that judgment for sure. At least your docs are quite good ๐Ÿ™‚

huthayfa20:05:29

hello guys, I am new to specter library. does anyone of you know which function is used to navigate the entire data structure tree and manipulate specific key

huthayfa20:05:20

without providing a path to the key

tanzoniteblack20:05:27

@huthayfa.ainqawi that's a little vague, can you give a minimal example of what you're working with and what you're trying to get to?

huthayfa20:05:15

{ "key": "hsq.contentjsonsample.sampleKey", "value": { "links":[{"text":"anytext","url":"http://nowhere.com","precedence":"1"},{"text":"anytext","url":"http://nowhere.com","precedence":"2"}], "misc":[{"key":"keyName","value":"valuessssssss"},{"key":"keyName","value":"valuessssssss"}], "assets":[{"name":"facebooklogo","location":"/s3/cmb/facebooklogo.png","type":"image"},{"name":"mypdf","location":"/pdfLocation","type":"pdf"}], }, "language":"EN", "shortName": "my Sample Json key", "description": "my Sample Json key explain why this key" }

huthayfa20:05:46

wherever there is assets key, I want to manipulate it

tanzoniteblack20:05:44

that said, walker is generally something I consider a "I have no idea what data's coming in, and I have no control over the format, and I'm ok with accidentally manipulating other keys that just happen to be called that", which is pretty heavy handed & crude

tanzoniteblack20:05:29

so if you can narrow your path down to more (like, assets will always be inside a map stored at links, or something) it can help to prevent random bugs

schmee20:05:44

you donโ€™t need specter for this, you can use update from core: (update your-map :assets update-fn)

tanzoniteblack20:05:17

@schmee update will only do it if you are directly manipulating a map, not if you need to find a map nested in a bigger data structure

huthayfa20:05:29

@schmee does update do a nested map search

tanzoniteblack20:05:29

(or multiple maps nested in a bigger structure)

schmee20:05:26

well, you need to specify what this larger data structure looks like in order to get a sensible answer

huthayfa20:05:03

I don't know where the assets happen in the structure, maybe at second or third level

huthayfa20:05:10

it depends on the jsonSchema

nathanmarz20:05:59

@huthayfa.ainqawi this code will run on every nested assets key with a walk that descends into all collections and map values (but not map keys):

(def NESTED-MAPS
  (recursive-path [] p
    (cond-path map? (continue-then-stay MAP-VALS p)
               coll? [ALL p]
               )))

(transform [NESTED-MAPS (must "assets")] my-transform-fn data)

๐Ÿ’ฏ 4
๐Ÿ‘ 4
huthayfa20:05:09

so the value returned from the NESTED-MAPS will replace the current value, right ?

huthayfa20:05:50

oh sorry, I didn't see my-transform-fn

huthayfa20:05:05

@nathanmarz thank you so much