Search code examples
functionvectorsyntax-errorjuliadeclare

in julia 1.0, what new syntax? error: { } vector syntax is discontinued


i'm using julia 1.0 and have a error, syntax: { } vector syntax is discontinued with this code below:

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)

i searched for function and method julia syntax but don't have any idea. Please help me solve this error, thanks. Update:

I still tried to convert it to 1.0 and detected that the source code causing {} vector syntax error is discontinued. It is below:

pColor = {"r>-", "bo--","kx-.","gd-", "c^--","m*-.","rs--","gp-.","bv-", "kh--","c+-.","m.-",};

Can you help me fix it in new syntax?


Solution

  • Use where operator instead like this:

    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}
    

    assuming you have a FloatingPoint type defined (in Base an equivalent would be Real or AbstractFloat depending on what you exactly want to accept).

    Here https://docs.julialang.org/en/latest/manual/methods/#Parametric-Methods-1 is a relevant section of the Julia manual explaining how to define parametric methods.