[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Confusion Over Keyword Arguments

Berger, Daniel

3/2/2006 4:09:00 PM

> -----Original Message-----
> From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
> Sent: Thursday, March 02, 2006 9:05 AM
> To: ruby-talk ML
> Subject: Re: Confusion Over Keyword Arguments
>
>
> On Fri, 3 Mar 2006, Berger, Daniel wrote:
>
> >> -----Original Message-----
> >> From: Yukihiro Matsumoto [mailto:matz@ruby-lang.org]
> >> Sent: Wednesday, March 01, 2006 4:46 PM
> >> To: ruby-talk ML
> >> Subject: Re: Confusion Over Keyword Arguments
> >
> > <snip>
> >
> >> |How about "=" for keyword arguments instead
> >> |(such as in python)?
> >>
> >> Unfortunately, assignments are legal in argument list in Ruby.
> >>
> >> matz.
> >
> > That can be made to work, with the understanding that '='
> in a method
> > call means 'keyword argument', not 'assignment', since there is no
> > point in doing an assignment in a method call.
> >
> > # Method definition, '=' means assignment (of default value): def
> > foo(bar, baz = 3)
> > ...
> > end
> >
> > # Method call, '=' means keyword
> > foo(baz = 5, bar = 2)
>
> but is
>
> foo baz = 5, bar = 2
>
> a, b = foo(baz = 5), (bar = 2)
>
> or
>
> a = foo( (baz = 5), (bar = 2) )
>
> ??

Second one.

Dan


2 Answers

Ara.T.Howard

3/2/2006 4:18:00 PM

0

Berger, Daniel

3/2/2006 4:23:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Fri, 3 Mar 2006, Berger, Daniel wrote:
>
>>>> # Method definition, '=' means assignment (of default value): def
>>>> foo(bar, baz = 3)
>>>> ...
>>>> end
>>>>
>>>> # Method call, '=' means keyword
>>>> foo(baz = 5, bar = 2)
>>>
>>>
>>> but is
>>>
>>> foo baz = 5, bar = 2
>>>
>>> a, b = foo(baz = 5), (bar = 2)
>>>
>>> or
>>>
>>> a = foo( (baz = 5), (bar = 2) )
>>>
>>> ??
>>
>>
>> Second one.
>
>
> but that's a problem no? number two is the same as this
>
> baz = 5
> bar = 2
> a = foo baz, bar

No, then they become positional. That's the same as foo 2, 5.

> see, when on writes
>
> foo baz = 5, bar = 2
>
> it's ambiguous if those assignments are part of a method call or not. bar
> escpecitally, it could easily be considered an assignment statement (bar=2)
> that's part of a parrallel assignment statement.
>
> or am i missing something?

The parser just has to be trained well enough. :)

That being said, perhaps using '=' as a keyword operator would just cause too
much confusion amongst the Ruby community. I know some people hate changing
behavior based on context.

Regards,

Dan