Is there anything in julia at the moment, that allows statements to be printed that give an idea of what is going on inside a function, only if the script or function is run during a debug mode?
Something like @debug println("Finished looping: i is $(i)")?
I just wrote my own trivial macro for that, which I use in conjunction with my little https://github.com/ScottPJones/StringUtils.jl (unregistered) package to get easily formatted debugging output.
const global debug = [false]
macro deb(str)
:( debug[] && println($(esc(str))) )
end
and in the code I have things like:
@deb(u"These are floats: \%8.2f(1.2345), \%8.3f(9.8765)")
and get nicely formatted output like:
These are floats: 1.23, 9.877
Then to enable debugging output of that module, I simple do: Foo.debug[] = true.
We ended up coming up with our own macros for logging also (with a bit of weird syntax magic I got from my friends on the JuliaLang/julia - Gitter Gitter chat room. @error(()->errorcode, message), @fatal(()->errorcode, message), @warn(()->errorcode, message), @info(()->errorcode, message)
The macro doesn’t execute the anonymous function, but instead uses it to get the __FILE__ and __LINE__ information, which unfortunately is otherwise unavailable from within a macro call (actually just one of them isn’t).
We use other flags and level settings to determine whether the macros 1) get compiled into the code (for warning and info messages) or 2) it is logged or not (run-time check based on level/flags)