Is there some way to break completely out of Infiltrator
’s @infiltrate
mode and return to the REPL, not executing any further code? Just like a “stop” button would in most IDEs’ debugging modes.
I see the @exit
macro, but that seems to only disable all @infiltrate
macros while continuing to execute all the code scheduled to execute.
The closest I’ve come is @exit
and then hit Control-C, but that’s very unreliable (sometimes the code isn’t easily stopped with a signal) and sometimes really undesirable (if I know the code is going to do something I really don’t want it to do).
Maybe throwing an exception somehow? A manual error()
seems to just give me the infil>
prompt again.
How about this macro? After @exit
, the code asks the user if the program execution should be stopped.
macro my_infiltrate()
quote
@infiltrate
println("Stop execution? [Y/N]")
response = readline(stdin)
if lowercase(response[1]) == 'y'
error("User requested stop.")
end
end
end
Test:
julia> function f(x)
x_plus_1 = x + 1
@my_infiltrate
return x_plus_1^2
end
f (generic function with 1 method)
julia> f(3)
Infiltrating macro expansion
at REPL[2]:3
infil> x_plus_1
4
infil> @exit
Stop execution? [Y/N]
y
ERROR: User requested stop.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] macro expansion
@ ./REPL[2]:7 [inlined]
[3] f(x::Int64)
@ Main ./REPL[3]:3
[4] top-level scope
@ REPL[4]:1
[5] top-level scope
@ none:1