The exception is a little bit confusing... ;)
The error is, that keyword arguments need a default value.
This version should work:
type Foo

  bar

  baz


  Foo(;bar=1, baz=2) = new(bar, baz)

end


Am Sonntag, 2. November 2014 19:05:37 UTC+1 schrieb Kevin Owens:
>
> 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")
>
>
>
>

Reply via email to