Fork me on GitHub
#clojure
<
2022-07-26
>
Quentin Le Guennec07:07:47

Is there a way in cider, when using a library A in an application B, to modify the source code of A, eval the modification, and see that modification in B?

rolt08:07:20

sesman-link-with-buffer (or its variants)

imre09:07:39

When performance tuning hot paths, is it worth extracting invocations of fns like constantly or fnil where possible?

(defn foo [coll]
  (->> (mapv (constantly nil) coll)
       ,,,
       ,,,))

;; is this worth extracting on a hot path?

(let [->nil (constantly nil)]
  (defn foo [coll]
    (->> (mapv ->nil coll)
         ,,,
         ,,,)))

delaguardo09:07:46

in the first example (constantly nil) is executed once. it is not on the hot path. So how you construct that function doesn’t impact performance

Ben Sless09:07:53

But it's called every time foo is called, so foo is called on the hotpath, the allocation and optimization of constantly nil can be measured If your path is really hot, you can provide an explicit arity constantly, which is less idiomatic but will avoid allocation for every call

Ben Sless09:07:22

because constantly takes [& args], so every call will do a little allocation

p-himik09:07:00

> which is less idiomatic Which is also debatable, even now. :) I remember partial and comp (outside of transducers) catching some flack from the maintainers, but I think constantly was also in there.

Ed09:07:52

I would have thought you'd get a bigger impact switching to transducers rather than having a number of intermediate sequences. But isn't the only real answer "measure it and see"?

imre10:07:18

Thanks for the tips folks

Dave Russell10:07:01

Here's an interesting find today, in case it's useful to anyone 🙂 -- we used to use medley/map-vals but have since updated to update-vals from 1.11. Turns out they have different behaviour, namely that update-vals will convert a sorted map into an unsorted map:

user> (def m (sorted-map :a 0 :b 0))
;; => #'user/m
user> (type m)
;; => clojure.lang.PersistentTreeMap
user> (type (update-vals m inc))
;; => clojure.lang.PersistentArrayMap
user> (type (medley.core/map-vals inc m))
;; => clojure.lang.PersistentTreeMap

👍 2
🤯 1
jumar11:07:46

That's an important gotcha - thanks for finding that! I used to use medley.core/map-vals a lot too. Will try to remember this one.

pppaul13:07:19

i'm not surprised, sorted maps seem like they are for debugging

pppaul13:07:34

also, your update function can throw errors on a sorted map, which for me is the common case. every time i use sorted maps they make my program explode in some way.

jumar08:07:57

@U01BP1CB37B could you perhaps submit a question on https://ask.clojure.org/ ? I think it would be useful to clarify whether this is the intended behavior or not.

Dave Russell08:07:53

Sure thing :thumbsup:

dpsutton20:07:49

I’ve got a namespace

(ns foo (:require [ns-1 :refer [Foo]]))
and need/want to change it to
(ns foo (:require [ns-2 :refer [Foo]]))
ns-unalias seems not equipped for the job. Is there any way to remove this binding on Foo so I can reestablish it without restarting the repl? Solved: ns-unmap . I always forget to (apropos "ns") to find that helpful bit. (thanks @ghadi)

seancorfield02:07:03

You might find inspiration in my "clean ns" REPL snippet for Calva: https://github.com/seancorfield/vscode-calva-setup/blob/develop/settings.json#L222

dpsutton05:07:56

i need to figure out a way to get a snippet system like that into inf-clojure. Also love the recursive taps

seancorfield05:07:21

I probably don't need the outer tap> but all my snippets start with a call to tap> and at least this means something gets tap'd when it is done.

seancorfield05:07:20

I wish snippets let you use actual code or at least multi-line strings (or maybe JSON does and I just don't know how? No, it doesn't 😞 )

skylize15:07:50

> I wish snippets let you use actual code - @U04V70XH6 You might be interested in this. https://github.com/BetterThanTomorrow/joyride

seancorfield16:07:39

@U90R0EPHA I already use Joyride (my vscode config repo on GH has my Joyride scripts in it), but custom REPL snippets auto-sync across machines whereas Joyride scripts do not 🙂

seancorfield16:07:47

See https://github.com/seancorfield/vscode-calva-setup/tree/develop/joyride/scripts for scripts that open Clojure or Java documentation directly inside VS Code

ghadi20:07:05

aliases are :as use ns-unmap for refers

👍 2
apt23:07:01

For a more brute solution, I sometimes use remove-ns and reload the whole ns