Imagine that you have many plotting calls that you’re using to debug the code that you are developing. At some point you want to be able to erase the plotting code quickly, commit the changes on git and reinsert the plotting code before development can continue.
I tried to solve this problem with a simple include as follows:
foo.jl
function foo()
# do something fancy
fancyobj = ...
include("plotting.jl")
# more fancy operations
fancyobj = ...
return fancyobj
plotting.jl
using PyPlot
# plotting code using variables defined in foo
plot(fancyobj)
xlabel(); ylabel()...
title(...)...
So whenever I need to commit my changes, I erase a single line include("plotting.jl"), commit and insert it back. The problem is that I am getting this UndefVarError for fancyobj. I assumed that include is equivalent to just pasting the code in place, is that incorrect? If this is the expected behavior, what is a better solution to the problem?
Are you sure it’s not plot that’s undefined? You’re using inside of a function. I am not sure that works. Just put using at the top scope of your module and it should be good.
function foo()
a = 2
include("plotting.jl")
end
foo()
plotting.jl
b = 2*a
$ julia foo.jl
Gives me:
ERROR: LoadError: LoadError: UndefVarError: a not defined
in include_from_node1(::String) at ./loading.jl:488
in foo() at /home/juliohm/Desktop/test/foo.jl:3
in include_from_node1(::String) at ./loading.jl:488
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
while loading /home/juliohm/Desktop/test/plotting.jl, in expression starting on line 1
while loading /home/juliohm/Desktop/test/foo.jl, in expression starting on line 6
Is there any other alternative that is simpler? I am trying to avoid writing a macro for every plotting snippet, or I probably don’t understand your proposal.