If you want all methods to use the same keyword arguments, define each
method with the same keyword arguments. You can declare keyword arguments'
types.
function foo(a::Int; test::Bool = true)
if test
a
else
0
end
end
function foo(a::AbstractFloat; test::Bool = true)
if test
a
else
100.0
end
end
foo(1)
1
foo(1,false)
0
foo(1,"grue")
ERROR
foo(1.0)
1.0
foo(1.0,false)
100.0
foo(1.0,"grue")
ERROR
On Tuesday, January 5, 2016 at 4:30:14 PM UTC-5, Michael Borregaard wrote:
>
> Hi, sorry I have a simple question, I have tried to RTFM.
>
> If I have a function with multiple methods and keyword arguments, all
> methods should share the same keyword args, right? How do I write this?
>
> function foo(a::Int; test = true)
> 2+a
> end
>
> function foo(a::AbstractFloat #how do I continue this line?
>
> In my real-world example I have multiple methods and a long list of
> keyword arguments.
>
> Thanks!
>