Fork me on GitHub
#babashka
<
2023-06-02
>
lauri02:06:14

Would it be useful to have gzip and gunzip functions in the babashka.fs library, like the existing zip and unzip functions? I can create an issue and a pull request to add these functions if you’re interested. Thanks for considering it!

minikomi03:06:54

I just used io/copy and GZIPInputStream , but a simple fs/(un)gzip might be useful to fill out the api

Somi Cho11:06:26

made a little something with babashka today πŸ˜€ https://github.com/somecho/utility-scripts#depo It's a util to add dependencies to a clojure project e.g. depo add reagent

πŸŽ‰ 8
borkdude11:06:48

Nice! Note that #C03KCV7TM6F also does exactly that:

neil dep add reagent/reagent

teodorlu12:06:07

Even though I already use Neil and https://github.com/teodorlu/neil-quickadd for dependencies already, I found it really interesting to read your code. It's so readable and straightforward! I didn't expect that neil dep add could be implemented in one page of code. (Though Neil supports finding dependencies on other places than Clojars)

borkdude12:06:31

neil also preserves whitespace/formatting

βœ”οΈ 2
Somi Cho12:06:24

what, how come I've never heard of neil? πŸ˜† This is great!

❀️ 2
Somi Cho12:06:25

ah another difference is that babashka-neil add deps to only deps.edn ?

borkdude12:06:43

@U059WGT3F7C You can specify --deps-file

Somi Cho13:06:51

@U04V15CAJ will project.clj files work too?

borkdude13:06:03

I do have this slightly related util: https://github.com/borkdude/lein2deps, but it only works one way

amithgeorge11:06:18

hi, I have code like below

(let [span-attributes {:some-key "some-value"}]
  (telemetry/with-span "SPAN_NAME" span-attributes 
	(... some block of code)))
I wish to create a list of all keys in the attributes passed to with-span . I would like to do this at build time. I tried grasp and using it I could get the span-attributes , but how do I resolve that binding to its value, ie the actual hash-map? Should I be using some other tool instead of grasp?

borkdude11:06:08

you could combine this with #clj-kondo :locals analysis: https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md

borkdude11:06:38

so find all the callsites of with-span (you can also do this with clj-kondo) and then find the local as argument and then find the local-definition, then read the expression at the location of the local-definition (e.g. using rewrite-clj or edamame, etc)

amithgeorge12:06:20

Interesting. This gives me something to explore. I will likely have doubts on how to do > then find the local-definition, then read the expression at the location of the local-definition but let me try on my own first. Thanks!

borkdude12:06:03

Feel free to come back with more questions

amithgeorge13:06:44

Using the clj-kondo analysis I found the location of the local definition.

{:end-row 794,
 :scope-end-row 876,
 :name span-attrs,
 :scope-end-col 55,
 :filename "src/some-path.clj",
 :str "span-attrs",
 :col 9,
 :id 287,
 :end-col 19,
 :row 794}
However how do I read the expression using edamame and the above info? Reading the edamame docs and experimenting with it, I am not sure how to get to line number 794 or read the expression hashmap there.

borkdude13:06:57

@U0A5B1LJU It's probably best to use rewrite-clj and write a loop like this: https://github.com/borkdude/carve/blob/cb621317ae1582869c8bd8f1a47cf57a3598d803/src/carve/impl.clj#L124 Just parse top level expressions until you find the one with the right row + end-row and then search for the sub-expression with the right location and then stringify that

borkdude13:06:23

A similar thing can be done with edamame

borkdude13:06:54

Let me write an edamame example for you

gratitude-thank-you 2
amithgeorge14:06:03

> Just parse top level expressions until you find the one with the right row + end-row and then search for the sub-expression with the right location and then stringify that thank you for this algorithm. I managed to write some hardcoded code using rewrite-clj that gave the expected answer. now to refine it further. gratitude-thank-you

amithgeorge14:06:47

with edamame, I couldn't figure out how to get the end-line number. with rewrite-clj, their position-span function helped a lot.

borkdude14:06:09

with edamame, the end-line number is on the metadata of the parsed form :)

borkdude14:06:19

sorry, I got distracted, but glad you figured it out

πŸ‘ 2
amithgeorge14:06:59

I did check the meta. In the readme, it shows the start and end line numbers. However, when I was trying it, I was only getting a line number. I must have been doing something wrong Will check it later.

borkdude14:06:53

user=> (require '[edamame.core :as e])
nil
user=> (meta (e/parse-string "foo"))
{:row 1, :col 1, :end-row 1, :end-col 4}

πŸ‘ 2
borkdude14:06:58

end-row and end-col

amithgeorge14:06:27

You are right. I misunderstood this as a recommended set of options

{:all true
 :row-key :line
 :col-key :column
 :end-location false
 :location? seq?}
with this I was getting only the start line number and column πŸ™‚ My bad for misreading the docs. Thanks!