Debug checks without output

If you change the macro to:

macro debug_code_block(expr)
    USE_DEBUG_CODE_BLOCKS || return nothing
    return :($(esc(expr)))
end

it works:

julia> const USE_DEBUG_CODE_BLOCKS = true;

julia> macro debug_code_block(expr)
           USE_DEBUG_CODE_BLOCKS || return nothing
           return :($(esc(expr)))
       end;

julia> @debug_code_block begin
           1 != 1 || throw("ooops!")
       end
ERROR: "ooops!"
Stacktrace:
 [1] top-level scope
   @ REPL[3]:2
julia> const USE_DEBUG_CODE_BLOCKS = false;

julia> macro debug_code_block(expr)
           USE_DEBUG_CODE_BLOCKS || return nothing
           return :($(esc(expr)))
       end;

julia> @debug_code_block begin
           1 != 1 || throw("ooops!")
       end

julia>

Note that you need to restart Julia when toggling like this.

3 Likes