From: Eric Mahurin Date: 2005-07-20T03:32:02+09:00 Subject: RCR: required args after optional ones (was Re: [RCR] nil for unassigned keys) --- Daniel Brockman wrote: > Hi Eric, > > > I thought you were going to submit an RCR for this (not > > too related to the original RCR topic of this thread - nil > > for unassigned keys - of a hash). > > I know, I'm sorry. As I said earlier in this thread, > > Myself> That reminds me, I promised I would write an RCR for > Myself> allowing trailing argument after the splatting one. > > Myself> It was said that optional arguments should be > Myself> allowed before the splat, but not after it. > > Eric, what is your opinion on this? Do you think these > > def foo(a, b=nil, c, d=nil, e) ... end don't like it - too ambiguous. Does b or d get assigned when you have 4 args? > def bar(a, b=nil, *c, d=nil, e) ... end also don't like it - too ambiguous. Does b or d get assigned when you have 3 args? > def baz(*a, b=nil, c=nil) ... end maybe. you could handle this if optional args have priority over splats. > should all be allowed? > > If so, then which variable, b or c, should be bound when > invoking baz with one argument? The obvious answer is b, > but you could argue that c makes more sense, since c is > farthest from the splat. I was thinking c to be symmetrical with optionals coming before the splat. I think the meat of this RCR should handle these cases: def f(a, b, c=c0, d=d0, y, z) ... end def f(a, b, *m, y, z) ... end def f(a, b, c=c0, d=d0, *m, y, z) ... end I think these are pretty clear: y and z get the last 2 args and the rest of the args are handled as they are now. I think this would be a bit more controversial: def f(a, b, *m, w=w0, x=x0, y, z) ... end In this case, after grabbing a, b, y, and z from the args, x would have priority over w and w over m. That would be symmetrical with optional args coming before the splat, but confusing. Especially when you might be confused as to whether w or x should have priority (as you discussed above). What case do you have where you want optional args after the splat? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com