Struct default value in constructor

If I understand your request correctly, a 2-argument outer constructor does what you’ve asked and there’s no need to fiddle with inner constructors. After all, you said you wanted a default value rather than it to always be exactly a particular value (which is where an inner constructor would have been useful).

struct Foo
    bar
    baz
    qux
end
Foo(bar,baz) = Foo(bar,baz,bar+baz)

Foo(1,2) # == Foo(1, 2, 3)
Foo(1,2,4) # == Foo(1, 2, 4)
6 Likes