From: Eric Mahurin Date: 2005-07-20T00:58:08+09:00 Subject: Re: [RCR] nil for unassigned keys --- Daniel Brockman wrote: > Thank you for your comments. > >> This would also reasonably mean that mixing optional and > >> mandatory arguments would become allowed: > >> > >> def bar(a, b=nil, c, d=nil, e) ... end > >> > >> bar 1 # ArgumentError > >> bar 1, 2 # ArgumentError > >> bar 1, 2, 3 # a=1, b=nil, c=2, d=nil, e=3 > >> bar 1, 2, 3, 4 # a=1, b=2, c=3, d=nil, e=4 > >> bar 1, 2, 3, 4, 5 # a=1, b=2, c=3, d=4, e=5 > > > > I don't like this. It is hard to see which value is put > > into which parameter. Picking some arguments from the left > > and from the right and stuffing the rest in the splatted > > parameter is easier to grasp, at least for me. > > Then what about this? > > def baz(a, b=nil, c) ... end > > Isn't that just as easy to grasp as this? > > def baz(a, *b, c) ... end > > > I think the chances to get the RCR accepted are higher if > > you drop this feature. > > You may be right. But I think restricting this to “only if > there's a splat argument somewhere!” is pretty arbitrary. > > If you wanted the semantics of this, > > def baz(a, b=nil, c) ... end > > you'd have to write it like this, > > def baz(a, *dummy, b=nil, c) > dummy.empty? or raise ArgumentError > ... end > > which seems pretty annoying-for-no-reason. Daniel, 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). Here is what was said in the thread "Re: iterators and block arguments" (which covers your concern above): --- Eric Mahurin wrote: > --- Daniel Brockman wrote: > > > Maybe this syntax could be adopted? > > > > def foo a, b, *args, c, d; ... end > > I want that too. It would be nice for the []= method where > the > value is always the last argument. Or any method where you > want optional arguments first or in the middle. > > In general, this: > > def foo a, b, c=x, d=y, *other, e, f > ... > end > > should be equivalent to: > > def foo a, b, *remaining > e,f = remaining.slice!(-2,2) > c = remaining.empty? ? x : remaining.shift > d = remaining.empty? ? y : remaining.shift > other = remaining > ... > end > > Want to submit an RCR for this? I've already done my fair > share. ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs