type Mesh
var1
var2
..
Mesh() = new()
end

Will do the trick.
This will overwrite the default constructor, though.
If you want to have it back, the easiest way to do it would be this:

type Mesh
var1
var2
...
Mesh(varargs...) = new(varargs...)
end

now you can write:
m = Mesh()
m.var1 = ...
x = m.var2 # ERROR: undefined reference 

Best,
Simon



Am Samstag, 20. Juni 2015 21:43:03 UTC+2 schrieb Stef Kynaston:
>
> I feel I am missing a simpler approach to replicating the behaviour of a 
> Matlab structure. I am doing FEM, and require structure like behaviour for 
> my model initialisation and mesh generation. Currently I am using composite 
> type definitions, such as:
>
> type Mesh
>     coords       :: Array{Float64,2}      
>     elements   :: Array{Float64,2}      
> end
>
> but in actuality I have many required fields (20 for Mesh, for example). 
> It seems to me very impractical to initialise an instance of Mesh via
>
> mesh = Mesh(field1, field2, field3, ..., field20),
>
> as this would require a lookup of the type definition every time to ensure 
> correct ordering. None of my fields have standard "default" values.
>
> Is there an easier way to do this that I have overlooked? In Matlab I can 
> just define the fields as I compute their values, using "Mesh.coords = 
> ...", and this would work here except that I need to initialise Mesh before 
> the "." field referencing will work.
>
> First post, so apologies if I have failed to observe etiquette rules. 
>

Reply via email to