下面的代码抛出一个"UndefVarError: g not defined“
function asdf()
if true
f(t) = t
else
g(t) = t
f(t) = g(t)
end
return f
end
w = asdf()
w(1)但通过将f(t) = g(t)替换为f= g,它是可行的。为什么?
发布于 2018-09-09 06:55:52
这是一个已知的错误https://github.com/JuliaLang/julia/issues/15602。
简短的建议是,不要定义一个在函数体中两次引用方法表的函数。取而代之的是,使用一个变量,在分支中为其分配两个不同的函数(具有不同的名称或匿名)。
在此问题得到解决之前,您应该做的是:
function asdf()
if true
f = t -> t
else false
g(t) = t
f = g(t)
end
return f
endhttps://stackoverflow.com/questions/52239198
复制相似问题