Whoops, I meant to say "only the call *to* fun3 would need to be modified."
--Peter On Thursday, October 9, 2014 1:35:54 PM UTC-7, Peter Simon wrote: > > Could you use a splatted final optional argument as follows? > > function fun3(; kw1 = 1, kw2 = 2, kw5 = 8, kw6 = 4, d...) > fun2(; kw1 = kw1, kw2 = kw2, d...) > end > function fun2(; kw1 = 1, kw2 = 2, d...) > fun1(; kw1 = kw1, kw2 = kw2, d...) > end > function fun1(; kw1 = 1, kw2 = 2, kw3 = 3) > kw1 + kw2 + kw3 > end > > println(fun3()) # -> 6 > println(fun3(kw3=4)) # -> 7 > > > This would allow adding any number of additional keyword arguments to fun1 > and only the call in fun3 would have to be modified. > > --Peter > > On Thursday, October 9, 2014 1:09:37 PM UTC-7, Andrei Berceanu wrote: >> >> Ah ok, I read that as if keywords were the solution to my problem, but >> alas, no. Are there any design plans for this? Should I open an issue? >> >> //A >> >> On Thursday, October 9, 2014 10:05:26 PM UTC+2, Stefan Karpinski wrote: >>> >>> The Options package was developed before keywords existed. >>> >>> On Thu, Oct 9, 2014 at 4:02 PM, Andrei Berceanu <[email protected]> >>> wrote: >>> >>>> Tim, what do you mean by "people have moved away from it now that we >>>> have keywords"? In my example I do use keywords (in fact that is the only >>>> thing I use), notice the ";" at the begining of each function argument >>>> list. >>>> >>>> //A >>>> >>>> >>>> On Thursday, October 9, 2014 9:33:00 PM UTC+2, Tim Holy wrote: >>>>> >>>>> While people have moved away from it now that we have keywords (for >>>>> some good >>>>> reasons), the Options.jl package might be worth a look in this >>>>> specific case. >>>>> >>>>> --Tim >>>>> >>>>> On Thursday, October 09, 2014 03:14:52 PM Stefan Karpinski wrote: >>>>> > Yes, this is a major problem, but I'm not sure what the fix is. It's >>>>> a >>>>> > serious language design issue and I'm not aware of any languages >>>>> that have >>>>> > good solutions. >>>>> > >>>>> > On Thu, Oct 9, 2014 at 3:09 PM, Andrei Berceanu < >>>>> [email protected]> >>>>> > >>>>> > wrote: >>>>> > > I often find myself passing long lists of parameters from one >>>>> function to >>>>> > > another. A simple, contrived example would be the following >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > *function fun3(; kw1 = 1, kw2 = 2, kw5 = 8, kw6 = 4) fun2(; kw1 >>>>> = kw1, >>>>> > > kw2 = kw2)endfunction fun2(; kw1 = 1, kw2 = 2) fun1(; kw1 = >>>>> kw1, kw2 = >>>>> > > kw2)endfunction fun1(; kw1 = 1, kw2 = 2, kw3 = 3) kw1 + kw2 + >>>>> > > kw3end*This results in code which is not easy to maintain. Notice >>>>> that >>>>> > > kw1 and kw2 are common to all 3 functions. Is there a way to pass >>>>> the two >>>>> > > of them (or more!) automatically? The way the code is written now, >>>>> if I >>>>> > > decide I want kw3 of fun1 to be changeable from fun3, I need to >>>>> change >>>>> > > the code in various places (in bold) -- very bug prone: >>>>> > > >>>>> > > *function fun3(; kw1 = 1, kw2 = 2, kw5 = 8, kw6 = 4* >>>>> > > *, kw3=3) fun2(; kw1 = kw1, kw2 = kw2* >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > *, kw3=kw3)endfunction fun2(; kw1 = 1, kw2 = 2, kw3=3) fun1(; >>>>> kw1 = >>>>> > > kw1, kw2 = kw2, kw3=kw3)endfunction fun1(; kw1 = 1, kw2 = 2, kw3 = >>>>> 3) >>>>> > > kw1 + kw2 + kw3end* >>>>> > > Tnx, >>>>> > > //A >>>>> >>>>> >>>
