Help with updating a legacy Julia code

Hi all,

I’m completely new to Julia.

I’ve got a Julia simulation code that seems to have been written in an old version of Julia. Thus, it uses a lot of deprecated syntax which fails to execute in the version I have (which is 1.3.0).

I’ve managed to carefully search for the compilation errors and update the code to reflect the current Julia syntax. However, there’s this piece of code that, being a total noob to Julia, I’m unable to understand.

This is the offending line of code:

rnew = drmax.(rand(nDim)-0.5);*

which results in the following error:

ERROR: LoadError: MethodError: no method matching -(::Array{Float64,1}, ::Float64)
Closest candidates are:

  • -(!Matched::Float64, ::Float64) at float.jl:403*
  • -(!Matched::Complex{Bool}, ::Real) at complex.jl:303*
  • -(!Matched::Missing, ::Number) at missing.jl:115*

Could anyone point me to how I can fix this so that it runs?

Thank you!

You probably want:

rand(nDim) .- 0.5

See Functions · The Julia Language

Also note that Julia version 0.7 is useful for upgrading older versions, because it contains deprecation warnings to help you.

In your case, running the code in Julia 0.7 produces the following:

julia> rand(nDim)-0.5
┌ Warning: `a::AbstractArray - b::Number` is deprecated, use `a .- b` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
5 Likes

Thank you! Looks like it dit it.