我有以下代码:
@time begin
results = nothing
for i in 1:3
if results == nothing
results = DataFrame(A=1, B=2)
else
results = vcat(results, DataFrame(A=1, B=2))
end
end
end
没有@time begin/end
部分,代码运行良好。
但是,在@time begin/end
部分,我得到了UndefVarError: results not defined
。
任何人都知道发生了什么事吗?
答案 0 :(得分:0)
在我看来,您存在范围界定错误。您对Boss1.some_member
的分配发生在该块的其余部分无法访问的范围内。您可以通过指定在本地范围内进行分配来解决此问题:
bool Employee::evaluate_salary_vs_sales();
请注意,仅使用results
块而不使用@time begin
local results = nothing
for i in 1:3
if results == nothing
results = DataFrame(A=1, B=2)
else
results = vcat(results, DataFrame(A=1, B=2))
end
end
end
也会得到相同的错误。