Why mutable struct cannot be defined inside a function in Julia?
function test()
mutable struct ABC
x
y
z
a
end
end
throws error:
ERROR: LoadError: syntax: "struct" expression not at top level
But if the struct is global that is outside the function and accessed inside function, the code works fine.
x
,y
,z
,a
beforehand, there's no need to define the struct within the function in the first place. And then, what should the function return? A type? An instance? – Conciliatorstruct
block does not create instances of a type, it defines the type itself. It is similar to the difference between a class and an object of a class in OOP languages. – Kilmarx