Thursday, October 29, 2015

How to get caller function in Clojure

I posted this question on Clojurians slack channel.
What's clojure equivalent of ruby's `caller` method?
To put it another way, if a function is call from multiple places, at runtime, is there a way to print out caller for debugging purpose?
Thanks to Alex Miller. He answered
the Thread class has methods to inspect the stack
(Thread/dumpStack) will just dump that thread's stack to stderr
or (Thread/getStackTrace) gives you an array of StackTraceElement's that you can traverse and do whatever
Basically, we can just use Java's Thread class. To be more precise, getStackTrace is an instance method so we have to call it this way.
(.getStackTrace (Thread/currentThread))
We'll get back Java's array of StackTraceElement class.

You can copy and just use a function I wrote here

No comments:

Config number of file descriptors on Linux

Check file descriptor limit for a process. Vary depending on owner of the process $ cat /proc/{process-id}/limits Check current number of...