5

I need to get calling function name in Clojure. Something like combination of macro's implicit variable &form and *file* var. I need to get or infer function name from those variable or something else if possible. Will have to be non platform specific.

2 Answers 2

4
+100

This function already exists in the Tupelo library. There are two functions that are thin wrappers over tupelo.misc/stacktrace-info

They return a map of info about the current function (or its parent), like:

       {:ns-name     'demo.core'
        :fn-name     'add2'
        :class-name  'demo.core$add2'
        :file-name   'core.clj'
        :line-num    57
        :method-name 'invokeStatic' } 
Sign up to request clarification or add additional context in comments.

Comments

3

I think you will have to use the platform-specific

(-> (Throwable.) .getStackTrace) in java

and

(-> (js/Error.) .-stack) in js and work it out from those sadly.

I don't think there's anything platform agnostic.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.