Hi,
I wonder why line breaks are required when defining fields of a structure, and where this is documented:
julia> struct S
a
b
end
julia> struct S a b end
ERROR: syntax: extra token "b" after end of expression
julia>
Hi,
I wonder why line breaks are required when defining fields of a structure, and where this is documented:
julia> struct S
a
b
end
julia> struct S a b end
ERROR: syntax: extra token "b" after end of expression
julia>
You can use ;
instead of line breaks. Also consider
https://github.com/cstjean/QuickTypes.jl
Thank you, but I find it strange, documentation (Punctuation section) says:
semicolons separate statements [...]
OK, it’s not a hot topic, just curiosity
It’s only required between the fields themselves, so one can write struct A a end
.
I’m also interested to know why it’s required at all. Maybe the devs didn’t want to complicate parsing just to let people write code that’s harder to read
Subjective of course but struct A b c end
is arguably less readable than
struct A
b
c
end
Something like this would be hard to parse (but maybe not impossible) without new-lines:
julia> struct T
a::T where T<:Integer
b::U where U<:AbstractArray
end
This is not a topic about readability, but about parsing rules. Semicolon is ok for the preceeding example:
julia> struct S a::T where T<:Integer; b::U where U<:AbstractArray end
julia>