A stackoverflow post made me realize that pretty much all functionality 
needed to support eval functionality in a local scope already exists in the 
Debug package, and that it might be useful for other applications than pure 
debugging, such as logging or just trying to figure out how one's code 
works. I just released an update to the package which supports this.

The key new ingredient is the @localscope macro, which returns an object 
representing the local scope (and must be wrapped in a @debug or 
@debug_analyze macro to work).

Example:

    @debug_analyze function f(x)
        y = x+5
        @localscope
    end
    scope = f(2)

    @show scope[:x] scope[:y] # prints scope[:x] => 2
                              #        scope[:y] => 7
    scope[:y] = 3
    @show debug_eval(scope, :(x*y)) # prints debug_eval(scope,:(x * y)) => 6

The new @debug_analyze macro is introduced to only instrument as little as 
possible (no single stepping) and only in the scopes that can be seen by a 
@localscope invocation, and leave the rest of the code alone. Some more 
details can be found in this section 
<https://github.com/toivoh/Debug.jl#evaluation-of-code-in-local-scope> of 
the Debug package readme.

Thoughts? Is there more functionality in this direction that you would like 
to see? Or less?

Reply via email to