Fork me on GitHub
#clojure
<
2022-09-22
>
Yehonathan Sharvit10:09:51

How can I read tagged-literals in the REPL? E.g. I want to evaluate this expression in the REPL

{:my-date #clj-time/date-time "2022-09-21T23:32:07.810Z"}

bronsa10:09:59

you require the library that provides the reader for clj-time/date-time

bronsa10:09:10

which by the looks of it would be.. clj-time

Yehonathan Sharvit10:09:38

Is the data-readers.clj automatically loaded?

Yehonathan Sharvit10:09:30

Do I have to require a namespace from clj-time or is it suffcient that the JAR is in the class path?

bronsa10:09:59

should be pretty easy to try and see simple_smile

emilaasa10:09:03

I'm trying to remember the name of a software project in clojure where you could construct queries against your source code and find for example all the references to a specific namespace from a function's full call stack. Could anybody jog my memory here?

emilaasa10:09:52

Grasp was the one I was trying to grasp from the jaws of forgetfulness, thank you!

👍 1
Lone Ranger11:09:21

Danggg good stuff!

borkdude11:09:49

#grasp if you have any questions

borkdude13:09:07

I just published 0.1.4

borkdude19:09:14

Ah, if you want that kind of thing, I suppose there is also clj-kondo analysis output: https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md

Joel19:09:41

Related question, is there a way to do structural search/replace on clojure code?

borkdude19:09:54

@UH13Y2FSA Yes, you can use #rewrite-clj for this

Joel19:09:34

@U04V15CAJ I didn’t see that rewrite-clj had a pattern search, although kibit which builds on top of it does, although doesn’t expose the functionality directly, but might be the best to build on top of.

borkdude20:09:52

@UH13Y2FSA #lsp also builds on top of rewrite-clj + clj-kondo analysis and supports various refactorings

Ben Sless13:09:27

Why does hashing a function (via hasheq) ends up going through clojure.lang.Numbers.hasheq? How is function hash calculated?

quoll20:09:48

I don’t follow this question. (hash (fn [])) will go through clojure.lang.Util.hasheq(Object o). That method goes through several if blocks, before calling through to calling o.hashCode()

=> (let [a (fn [])] [(hash a) (.hashCode a)])
[745571392 745571392]
This returned the same number both times because both times it came from the underlying object .hashCode() Also, clojure.lang.Numbers.hasheq https://github.com/clojure/clojure/blob/5ffe3833508495ca7c635d47ad7a1c8b820eab76/src/jvm/clojure/lang/Numbers.java#L1151:
static int hasheq(Number x){
And because functions aren’t numbers this can’t get called. So… I’m confused about the question

Ben Sless04:09:28

Sorry, I should have clarified. I'm asking because reading the java code I see absolutely no reason to go through numbers hash, but when I profile I do see it, so something is playing tricks on me

quoll20:09:22

Strangeloop starts, and this channel becomes a ghost town. Weird :thinking_face:

👀 2
👻 2
lilactown21:09:12

(defn strange
  []
  (prn “help! I’m trapped”)
  (recur))

😆 7
lilactown21:09:23

Caught in a strange loop

uwo21:09:04

Any idea why a transducer-returning arities weren't included for update-vals/update-keys? I didn't see any discussion of it on the ticket: https://clojure.atlassian.net/browse/CLJ-1959

dpsutton21:09:20

How would you expect to use them? I’m not seeing how they would be transducers themselves

uwo21:09:45

In a transducing pipeline in place of map+kvp-destructuring:

(comp
    ;; ...
    (map (fn [[k v]]
           [(f k) v]))
    ;; ...
    )
= >
(comp
>     ;; ...
>     (update-keys f)
>     ;; ...
>     )

hiredman21:09:37

you need to use reduce-kv for that, which doesn't exist for transducers

uwo22:09:11

ah! that makes sense

hiredman22:09:23

(assuming you want update-keys to do something different than what the map destructuring does)

👍 1
dpsutton22:09:38

you want to use it like (map (partial update-keys f))?

dpsutton22:09:37

(i have the signature backwards. don’t use it enough to remember it)

uwo22:09:03

heh, same. I just reached for it for the first time, but realized I was in a transducing context. Still glad they're there!