Also check out Logging.jl, which does have macros for enabling/disabling printing/logging at different levels.
Kevin On Tue, Aug 19, 2014 at 3:09 AM, Ivar Nesje <[email protected]> wrote: > See also #7732 <https://github.com/JuliaLang/julia/issues/7732> > > I'm not sure why this is not getting traction. It seems like a useful > feature to me, but it probably doesn't seem to add much value, and it has > impact on the correctness of high performance Julia libraries. It should > probably be handled together in the same framework as other unsafe > optimizations like a better @inbounds behaviour for user defined functions > (see: #7799 <https://github.com/JuliaLang/julia/issues/7799>). > > Ivar > > kl. 12:00:44 UTC+2 tirsdag 19. august 2014 skrev Jan Kybic følgende: > >> 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 >> >
