Thanks, Tom. That's exactly what I'm looking for.
On Thursday, January 7, 2016 at 2:21:13 PM UTC-5, Tom Breloff wrote: > > Depending on how much performance you need, you could do something like: > > _f(a::A, b::B, c::C) = ... > > function f(args...) > a,b,c = A(1),B(1),C(1) > for arg in args > T = typeof(arg) > if T <: A > a = arg > elseif T <: B > b = arg > elseif T <: C > c = arg > end > end > _f(a,b,c) > end > > And if you need to do this in multiple places, I'm sure you could turn > this into a macro fairly easily. > > > On Thu, Jan 7, 2016 at 2:02 PM, Josh Day <[email protected] > <javascript:>> wrote: > >> Suppose I have a function that takes several arguments of different types >> and each has a default value. What is the best way to specify all possible >> methods where a user can specify an argument without entering the defaults >> that come before it? I don't want to force a user to remember the exact >> order of arguments. The example below may explain this better. >> >> type A >> a::Int >> end >> type B >> b::Int >> end >> type C >> c::Int >> end >> f(a::A = A(1), b::B = B(1), c::C = C(1)) = ... >> >> I would like the user to be able to call f(C(3), B(2))instead of f(A(1), >> B(2), C(3)). I could just implement the factorial(3)methods myself, but >> if I want to do this for 5 types, it means I'm writing 120 methods. >> >> Is this just a terrible idea and I should use keyword arguments? >> > >
