You need to give default values for each keyword argument: type Foo bar baz Foo(;bar=10, baz=1) = new(bar, baz) end
On Sunday, November 2, 2014 1:05:37 PM UTC-5, Kevin Owens wrote: > > I'm using Julia 0.3 something. > > If I make a composite type with many fields I may forget the order, but > remember their names. I'd like to use a constructor where I can use name > the arguments. > > Say I have the composite type > > type Foo > > bar > > baz > > end > > > How can I make a constructor that lets me do this > > myfoo = Foo(baz=1, bar=2) > > I expected this would work > > > type Foo > > bar > > baz > > > Foo(;bar, baz) = new(bar, baz) > > end > > > But when I run it I get > > ErrorException("syntax: invalid keyword argument bar") > > > I also tried > > > > julia> function Foo(;bar, baz) > > > Foo(bar, baz) > > > end > > > > > ErrorException("syntax: invalid keyword argument bar") > > > >