From: "Haase, Konstantin" Date: 2011-10-18T14:33:00+09:00 Subject: [ruby-core:40197] Re: [Ruby 2.0 - Feature #5454] keyword arguments From the current patch it seems to me that this would raise an ArgumentError, as it does now. Neither name nor age are "keyword arguments". There is no way to define keyword arguments without a default. Also, these are really named arguments in a Python sense, not keyword arguments in a Smalltalk sense. @Matz: def foo(bar: 42) bar end foo bar: nil The above should return nil IMHO, since this is also what I'd expect if it would be an options hash. Konstantin On Oct 17, 2011, at 22:27 , Evan Phoenix wrote: > Thanks for the translation! > > I've got a question about the proposal that will help me understand how it would be implemented. > > Given a method: > > def foo(name, age) > p [name, age] > end > > And then code that calls this method: > > arg = { :name => "Evan", :age => 32 } > foo(arg) > > Would this print out ["Evan", 32]? > > If so, this seems like a very big change that a lot of code written against 1.9 will not work with. > > Also, the example code in the proposal uses a form to call foo like this: > > foo(name: "Evan", age: 32) > > This reuses the 1.8/1.9 behavior of the implicit hash parameter. Does this mean that the implementation creates a hash on the caller side, which is then pulled apart by the called method? If so, these seems just like my first example, and would end up breaking a lot of code. > > > Because 1.9 introduces the new hash syntax, which programmers have begun using with the implicit hash parameter, I don't think that the syntax can be used again for keyword arguments without introducing an incompatible change. > > So, I'd like to suggest an alternative to this which uses a different (and thusly unambiguous) syntax: > > foo(name="Evan", age=32) > > I know that this is valid ruby code in 1.9, but it is extremely rare, much much more rare than the implicit hash parameter. Thusly it is safer and will not break 1.9 code. > > This form also allows for an implementation of keyword parameters that don't require creating a Hash object, which makes the code faster and more useful. > > If a truly new syntax must be introduced to be 100% backward compatible, I'd suggest: > > foo(name := "Evan", age := 32) > > := is already known in computing as a bind operator, and thus it is suited well to this task. > > Thank you for considering my proposal. > > - Evan > > -- > Evan Phoenix // evan@phx.io > > > On Monday, October 17, 2011 at 9:08 PM, Yukihiro Matsumoto wrote: > >> Hi, >> >> I should have posted in English at first. >> Thank you guys for translation. >> >> matz. >> >> In message "Re: [ruby-core:40191] Re: [Ruby 2.0 - Feature #5454] keyword arguments" >> on Tue, 18 Oct 2011 11:56:29 +0900, Yutaka Hara writes: >> | >> |Hi, >> | >> |2011���10���18���8:13 Evan Phoenix : >> |> This looks very interesting! Would someone be willing to translate to english? I've only got a vague idea of what is being discussed. >> |> >> |I and NaHi translated the mails. >> | >> |http://ruby-dev.info/posts/44602 >> | >> |-- >> |yhara (Yutaka HARA) > > >