The code that worked in 0.3:
type foo
bar::Int = 0
end
After migrating to Julia 0.4- produces errors like
julia4 test.jl
ERROR: LoadError: syntax: "bar::Int=0" inside type definition is reserved
in include at ./boot.jl:254
in include_from_node1 at loading.jl:133
in process_options at ./client.jl:306
in _start at ./client.jl:406
What does the error mean? How to fix it in 0.4-?
NB
I understand that it is a dev version. I also did googled and consulted the manual http://julia.readthedocs.org/en/latest/manual/types/
Ok, the thing I come up with is to use the constructor called new()
and a function (in type) with default (python/haskell-like) parameter values:
struct Foo
bar::Int
function Foo(bar=0)
new(bar)
end
end
x = Foo()
A shorter syntactical version is (thnx @ivarne)
struct Foo
bar::Int
Foo(bar=0) = new(bar)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With