From: Jean-Hugues ROBERT Date: 2002-04-16T15:47:19+09:00 Subject: RE: RCR: xx: yy as shorter notation for :xx => yy Hello, xxx: yyy as a shorter :xxx => yyy. About feature interaction with "keyword arguments" (aka "named arguments"). At 11:45 16/04/2002 +0900, you wrote: >Actually, since the current Ruby-way of faking out keyword arguments >are: > >def method(x=nil, y=nil, z=nil) > if x.kind_of? Hash > x,y,z = x[:x], x[:y], x[:z] > end > puts x, y, z >end > >1) method(:x=>1, :z=>2) >2) method(1,2,3) > >If you allowed a hash to be defined by: "key: value" > >How would you distinguish between that dynamically building a hash (1 >above) and your keyword argument idea in (3 below)? > >3) method(x: 1, z: 2) No easy answer I'm afraid. It is like having your cake and eating it too. One potential answer could be that it is the defined function that would tell the interpreter about the fact that it (the function) accepts keyword arguments (def xx( x:, y: = nil) end, for example). As a result the interpreter would automatically do what is currently done "by hand" as in the sample code. Overall this makes implementing keyword arguments something reasonably easy I guess. If mixing "keyword argument" and "argument" is not necessary then def xx:( x, y = nil) would do the job too, the ":" after the function's name tells that *all* arguments are keyword arguments. Another possibility, to distinguish a "call with keyword arguments" from a "call with on-the-fly hash", would be that it is the caller that tells the interpreter about the fact that it (the caller) is using keyword arguments. ex: method:( x: 1, z: 2). Here the ":" after the method name triggers the "call with keyword arguments". BTW: [x: "foo", y: "bar"] could also be a nice shorter [:x,"foo", :y,"bar"]. I think it is a common idiom in Lisp to have such lists with flat pairs of symbol + value. Some other languages have a "name" attached to every values. Jean-Hugues