Fork me on GitHub
#clojure
<
2019-12-02
>
borkdude11:12:19

With direct linking I get this:

(defn f [] 10)
(defn g [] (f))
(g) ;;=> 10
(defn f [] 11)
(g) ;;=> 10
But why does this return 11?
(def x 10)
(defn foo [] x)
(def x 11)
(foo)
11

borkdude11:12:05

it seems like foo is still going through the x var reference when not calling it as a function?

ghadi11:12:11

when a reference to a var is used as an expression direct linking does not apply @borkdude

ghadi11:12:22

it should be called "direct linkage of invocations"

borkdude11:12:29

aha... why is that?

ghadi11:12:14

direct linking is intended for linking to static methods when you call a var

ghadi11:12:27

instead of getting the arbitrary contents of a var

ghadi11:12:59

definitionally, getting the contents of something assumes indirection through the something box

ghadi11:12:56

your first example is an invoke (f) the second example is a var expr x

borkdude11:12:08

good to know. I have a clojure interpreter which directly links even var references, but maybe that's a little bit too greedy then

👀 4
borkdude11:12:56

so when you re-def something in Clojure, (def x 10) (def x 11) , the second time, x is still the same var object right?

borkdude11:12:14

user=> x
2
user=> (hash #'x)
126234454
user=> (def x 2)
#'user/x
user=> (hash #'x)
126234454

vemv12:12:33

I have a unit test that gets stuck while running. I want to determine in which function it got stuck. If I Ctrl+C while running lein test the-ns, the JVM succesfully quits, but no extra output is emitted or logged. I already have Thread/setDefaultUncaughtExceptionHandler in place. Is there a way to get a stacktrace on Ctrl+C, so that I see what work was being done?

vemv12:12:19

FWIW, Emacs offers this behavior on kill -USR2 (for Emacs itself, not clojure-wise). I guess that a profiler could let me visualize this precise thing? Long time no use

borkdude12:12:59

adding lots of printlns usually helps me in this case 😉

vemv12:12:44

bit of a large/complex system, with core.async abstractions and such but yes, ultimately can do!

rutledgepaulv13:12:58

It's possible there's special signal handling that might behave differently via Ctrl+C than interrupting programmatically. Try future and future-cancel at the top level of your test? Not quite sure of the setup you have but if your control thread is what's blocked that should help find where. If you just have a dead lock / loop in the background that won't help much since presumably you already know where control thread is stalled?

vemv13:12:53

I can't reachitect the app to make all core.async usages be sync defn calls instead... would be a lot of work

vemv13:12:39

YourKit thread inspection made it easy. Sometimes one has this irrational fear of trying new tools :)

👍 4
vemv13:12:02

@U5RCSJ6BB I see your edited suggestion now. Interesting technique, might try the next time

borkdude13:12:00

(clojure.repl/set-break-handler! #(throw (Exception. %))) and then pressing Ctrl-C throws an exception, while not exit-ing

4
👍 4
noisesmith00:12:03

you can get the stack traces of all running tasks with Ctrl-\ or the equivalent, sending the USER2 signal to the vm

🔝 4
noisesmith00:12:25

the jstack program does this, based on the PID of the vm

noisesmith00:12:09

and this is what happens when you send USER2 to emacs (emacs gives the signal to the nrepl client subprocess which knows what to do with it)

vemv01:12:25

Sounds useful thanks! I tried kill -USR2 now, it does nothing on my machine unfortunately And jstack failed with Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach symbolicator to the process But I'll note these down and try them in a leaner clojure process

noisesmith01:12:07

oh - it's not USER2 that makes the stack trace print, it's QUIT, numeric code 3

pez13:12:34

What is a good way to assert some specific ex-data in a deftest ? I would want something like thrown-with-ex-data?.

mpenet13:12:01

our exception helper lib also has something similar it's just a multimethod to extend, feel free to steal what you need. https://github.com/exoscale/ex/blob/master/modules/ex/src/clj/exoscale/ex/test.clj#L6

👍 4
pez13:12:48

@U45T93RA6, OMG, recently is an understatement. Looks perfect! I'll have a go.

pez13:12:25

@U050SC7SV thanks! I'll let myself get inspired. 😍

pez13:12:58

@borkdude: clj-kondo says thrown-ex-data?doesn't spark joy, but it do!

borkdude13:12:28

update the config

pez13:12:45

Me neither. 😃

borkdude13:12:38

But you can whitelist the symbol using the config for unresolved symbols

borkdude13:12:23

(clojure.test/is [thrown? thrown-with-msg? thrown-ex-data?])

pez14:12:22

Works like a charm. (Both the hedgehog and the kondo config.)

pez14:12:49

I might try to solve the assert-expr more generally some day, though. When I have eons or time. Haha.

stephenmhopper15:12:25

Hi, I have a series of task that can be executed (mostly) in parallel (some depend on others). Are there any basic Clojure DAG frameworks for doing things in parallel in one JVM?

vemv15:12:27

titanoboa?

stephenmhopper15:12:27

I’ve used Onyx in the past, but I think it might be too heavy for what I’m trying to achieve here.

Daniel Stephens16:12:35

oh, might have misunderstood the question, probably not applicable, mb