我正在使用julia 1.0并出现错误,syntax: { } vector syntax is discontinued
使用以下代码:
function abc{Ti<:Integer,Tf<:FloatingPoint}(Ns::Ti,rho::Array{Tf,1},
M::Array{Ti,1};Niter::Ti=5,rate::Tf=.5,Mc::Ti=2,mSparse::Ti=0,
strategy::Ti=2,Nmat=1)
我搜索了函数和方法julia语法,但没有任何想法。请帮助我解决此错误,谢谢。
更新:
我仍然尝试将其转换为1.0,并检测到导致{} vector 语法错误的源代码已停产。如下:
pColor = {“r>-”,“bo-”,“kx-。”,“gd-”,“c ^-”,“m *-。”,“rs-”,“gp-。 “,” bv-“,” kh-“,” c +-。“,” m.-“,};
您能帮我用新的语法修复它吗?
最佳答案
像这样使用where
运算符:
function abc(Ns::Ti,rho::Array{Tf,1},
M::Array{Ti,1};Niter::Ti=5,rate::Tf=.5,Mc::Ti=2,mSparse::Ti=0,
strategy::Ti=2,Nmat=1) where {Ti<:Integer,Tf<:FloatingPoint}
假设您定义了
FloatingPoint
类型(在Base中,根据您确切要接受的内容,等效项为Real
或AbstractFloat
)。https://docs.julialang.org/en/latest/manual/methods/#Parametric-Methods-1是Julia手册的相关部分,解释了如何定义参数方法。
关于function - 在julia 1.0中,什么新语法?错误: { } vector syntax is discontinued,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52652058/