Context
Currently,
(println "x is" x)
just prints out
x is 10
Now, what I want is something like this:
(my-println "x is" x)
to print out:
foo.clj:23> x is 10
Informally, I want my-println to append the _FILE_NAME_ and _LINE_NUMBER_ into my println.
Question:
I know how to use macros. However, I don’t know how to extract the _FILE_NAME_ and _LINE_NUMBER_ from the current location in Clojure (whereas C macros make this trivial to do). How do I get the current FILE_NAME_ and _LINE_NUMBER_ ?
Thanks.
Looking at this answer again much later, you can be a bit more clever if you like, reducing the runtime costs by interpolating the string constants at compile time:
As you can see from the macroexpansion, there is no longer any need to invoke relatively-expensive printf code at runtime: