Clojure function print character name and character value

I struggled to find an answer or develop a solution. I am trying to figure out how to make code that makes code in Clojure. For my first feat, I want a function that will print for stdout the symbol name and its value, useful for debugging. Example:

(def mysymbol 5) (debugging-function mysymbol) mysymbol: 5 

It makes sense? Thank you for your help.

Update after discussion

Here is the answer from @amalloy:

 (defmacro ? "A useful debugging tool when you can't figure out what going on: wrap a form with ?, and the form will be printed alongside its result. The result will still be passed along." [val] `(let [x# ~val] (prn '~val '~'is x#) x#)) 

So: (? myvariable)

+4
source share
1 answer

You can see a simple version of this that I wrote on github . The main thing is that you cannot do this with the function, but with a macro it is quite simple - you just need to get your quotation and unconditional right.

+6
source

Source: https://habr.com/ru/post/1382758/


All Articles