【发布时间】:2018-01-12 13:42:09
【问题描述】:
我有以下 julia 函数
function fakeseq()
let; global f(x)=unshift!(push!(x, 35) , 1);end; # not working
#let; global f; f=x->unshift!(push!(x, 35) , 1);end; # works fine
s1 = [rand(1:34) for i in 1:12];
s2 = [rand(1:34) for i in 1:7]
data = map(x->f(x), [s1, s2])
end
当我运行该代码时,我收到以下错误:
julia> fakeseq()
ERROR: MethodError: no method matching f(::Array{Int64,1})
The applicable method may be too new: running in world age 21823, while current world is 21824.
Closest candidates are: f(::Any) at REPL[1]:2 (method too new to be called from this world context.)
Stacktrace:
[1] _collect(::Array{Array{Int64,1},1},
::Base.Generator{Array{Array{Int64,1},1},##3#6}, ::Base.EltypeUnknown,
::Base.HasShape) at ./array.jl:488
[2] fakeseq() at ./REPL[1]:6
但是,# works fine 注释指示的 f 的第二个定义有效。我无法得到它们之间的确切区别,为什么会这样?
【问题讨论】:
-
查看Redefining Methods 上的 julia 文档。另外,我希望您会得到不同的结果,具体取决于 a) 您运行上述定义的顺序(确保您从新的 julia 会话开始。)
-
您也在使用 julia v0.6 吗?我没想到它会让你重新定义
f句号... -
@Alexander Morley 我正在使用 julia v0.6.2。问这个问题时,我的意思是我在新的 julia 会话中只使用了上述 let 块之一。