Hi to all,
I like to have asserts that I can switch on for debugging and switch off
later on for performance, to eliminate the run-time penalty. I could not
find this functionality in Julia, so I implemented it. My implementation is
attached. The usage is simple, similar to @assert:
include("debugassert")
switchasserts(true)
@debugassert(1==2)
switchasserts(false)
@debugassert(1==2)
The implementation is at
http://cmp.felk.cvut.cz/~kybic/share/debugassert.jl as well as below (I did
not manage to attach a file to this message).
This is my first macro in Julia, so it might not be optimal but seems to be
doing the job. Enjoy.
Could/should it be incorporated somewhere? The code is so small it does not
seem to be worth creating its own package.
Another idea along the same lines are debugging prints with assigned
priorities and/or attributes, with the user selecting what messages he
wants to see. Suppressed messages should have no overhead. I believe this
also does not exist in Julia, right?
Yours,
Jan
function switchasserts(doassert::Bool)
if doassert
# define debugassert as assert
@eval macro debugassert(ex,msgs...)
return :(@assert($(esc(ex)),$(msgs...)))
end
else
# define debugassert as empty
@eval macro debugassert(ex,msgs...)
return :nothing
end
end
end