First, here is a point that you probably already know: you can define another constructor for the type that takes zero arguments and fills the fields with default values. Perhaps that partly solves your problem?
Of course, in this zero-argument constructor, you still have to call the built-in constructor with a long list of comma-separated default values. This can be difficult for a human reader to parse, and it is also error-prone. To address the readability issue, I wrote a macro called modifyFields! that lets you use a keyword-style statement to modify fields of a composite type. Its intended purpose is a bit different from your request (it was intended to change fields of an immutable rather than initialize fields of a mutable) but it should also work as an initializer for mutable composite types. https://github.com/StephenVavasis/ModifyField.jl On Tuesday, November 3, 2015 at 12:17:05 PM UTC-5, Randy Zwitch wrote: > > I've been working on understanding some macro code I inherited, which (I > believe) essentially does this: > > type VegaAxis2 > _type::Union{AbstractString, Void} = "x" > scale::Union{AbstractString, Void} = "x" > orient::Union{AbstractString, Void} = nothing > title::Union{AbstractString, Void} = nothing > titleOffset::Union{Number, Void} = nothing > format::Union{AbstractString, Void} = nothing > ticks::Union{Number, Void} = nothing > values::Union{Vector, Void} = nothing > subdivide::Union{Number, Void} = nothing > tickPadding::Union{Number, Void} = nothing > tickSize::Union{Number, Void} = nothing > tickSizeMajor::Union{Number, Void} = nothing > tickSizeMinor::Union{Number, Void} = nothing > tickSizeEnd::Union{Number, Void} = nothing > offset::Union{Number, Dict{Any, Any}, Void} = nothing > layer::Union{AbstractString, Void} = nothing > grid::Union{Bool, Void} = nothing > properties::Union{Dict{Any,Any}, Void} = nothing > end > > Running the code above verbatim gives the following error: > > LoadError: syntax: "_type::Union{AbstractString,Void}=x" inside type > definition is reserved > while loading In[87], in expression starting on line 20 > > > I believe macro itself is simulating this behavior by writing out the > following and time VegaAxis2() is called: > > > VegaAxis2("x","x",nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing) > > > Long story short, why is the assignment behavior inside Composite Types > reserved? Is this always going to be the behavior, or will this restriction > be removed in the future, so that you can assign default values? > >
