Let’s say you have a couple example files:
# woof.jl
function println(foo::Module, bar::AbstractString)
"cool. cool. alright"
end
println() = println(Main, "huh?")
# bark.jl
println(a::Float64, b::Integer, c::String) = println(Main, c)
You now want to load them into a module, Moo.jl
:
# moo.jl
module Moo
cur_array = []
cur_files = ["woof.jl", "bark.jl"]
# for cur_file in cur_files
# include(cur_file)
# end
for cur_file in cur_files
open_file = open(cur_file)
cur_expr = parse(open_file)
while cur_expr != nothing
push!(cur_array, cur_expr)
cur_expr = parse(open_file)
end
close(open_file)
end
for cur_expr in cur_array
Moo.eval(cur_expr)
end
end
Why does this method of loading the files trigger an “explicitly define” error:
ERROR: LoadError: error in method definition: function Base.println must be explicitly imported to be extended
Whereas using the standard include(cur_file)
work perfectly?
// edit: println
could have just as well been print
, read
, countlines
, etc.