朱莉娅:缺失的一端在哪里?
Julia: where is the missing end?
我正在尝试将用 Python 编写的程序转换为 Julia。我最近 2 个小时一直在使用 Julia。
我的代码如下:
function spin_add(buff,clust,spins,padd)
if size(buff) == 0
return(clust)
else
i = buff[1][1] #row
j = buff[1][2]] #column
L = size(spins[1:1,:])
u = i-1
d = i+1
r = j+1
l = j-1
if i == L
d = 1
end
if i == 1
u = L
end
if j == L
r = 0
end
if j == 1
l = L
end
nei = [(u,j),(d,j),(i,r),(i,l)]
popfirst!(buff)
for site in nei
if site not in clust
if spins[site] == spins[i,j]
if rand() < padd
push(clust,site)
push(buff,site)
end
end
end
end
return(spin_add(buff, clust, spins, padd))
end
end
但是,我收到一条错误消息,指出未添加 end
。确切的错误是
syntax: "if" at In[10]:2 expected "end", got "]"
Stacktrace:
[1] top-level scope
@ In[10]:6
[2] eval
@ .\boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116
我不明白我必须在哪里添加 end
。
j = buff[1][2]-->]<-- #column
去掉多余的“]”应该可以解决问题。
我正在尝试将用 Python 编写的程序转换为 Julia。我最近 2 个小时一直在使用 Julia。
我的代码如下:
function spin_add(buff,clust,spins,padd)
if size(buff) == 0
return(clust)
else
i = buff[1][1] #row
j = buff[1][2]] #column
L = size(spins[1:1,:])
u = i-1
d = i+1
r = j+1
l = j-1
if i == L
d = 1
end
if i == 1
u = L
end
if j == L
r = 0
end
if j == 1
l = L
end
nei = [(u,j),(d,j),(i,r),(i,l)]
popfirst!(buff)
for site in nei
if site not in clust
if spins[site] == spins[i,j]
if rand() < padd
push(clust,site)
push(buff,site)
end
end
end
end
return(spin_add(buff, clust, spins, padd))
end
end
但是,我收到一条错误消息,指出未添加 end
。确切的错误是
syntax: "if" at In[10]:2 expected "end", got "]"
Stacktrace:
[1] top-level scope
@ In[10]:6
[2] eval
@ .\boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116
我不明白我必须在哪里添加 end
。
j = buff[1][2]-->]<-- #column
去掉多余的“]”应该可以解决问题。