[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[self.]setter vs. local variable initialization

Its Me

11/5/2004 2:30:00 PM

Will Ruby 2.0 continue to interpret
x = 5
as initializing a local variable vs. calling a setter method?

class A
def x=(a); end
def y(a); end
def foo
x = 5 # local var, not self.x=5
y(5) # self.y(5)
end
end



7 Answers

Yukihiro Matsumoto

11/5/2004 3:07:00 PM

0

Hi,

In message "Re: [self.]setter vs. local variable initialization"
on Fri, 5 Nov 2004 23:58:44 +0900, "itsme213" <itsme213@hotmail.com> writes:

|Will Ruby 2.0 continue to interpret
| x = 5
|as initializing a local variable vs. calling a setter method?

It will. x = 5 will be always interpreted as local variable
assignment, even when x= setter is defined.

matz.


Its Me

11/5/2004 9:35:00 PM

0

Thanks Matz.

Any chance the parenths/space requirement will go away in 2.0?

method (1, 2, 3)

"Yukihiro Matsumoto" <matz@ruby-lang.org> wrote in message
news:1099667201.686203.12635.nullmailer@x31.priv.netlab.jp...
> Hi,
>
> In message "Re: [self.]setter vs. local variable initialization"
> on Fri, 5 Nov 2004 23:58:44 +0900, "itsme213" <itsme213@hotmail.com>
writes:
>
> |Will Ruby 2.0 continue to interpret
> | x = 5
> |as initializing a local variable vs. calling a setter method?
>
> It will. x = 5 will be always interpreted as local variable
> assignment, even when x= setter is defined.
>
> matz.
>
>


Yukihiro Matsumoto

11/6/2004 12:30:00 AM

0

Hi,

In message "Re: [self.]setter vs. local variable initialization"
on Sat, 6 Nov 2004 06:38:41 +0900, "itsme213" <itsme213@hotmail.com> writes:

|Any chance the parenths/space requirement will go away in 2.0?
|
| method (1, 2, 3)

Not sure. Only if I can make yacc rules smart enough to parse/detect

method (arg1), arg2

matz.


Brian Candler

11/6/2004 1:38:00 PM

0

> |Any chance the parenths/space requirement will go away in 2.0?
> |
> | method (1, 2, 3)
>
> Not sure. Only if I can make yacc rules smart enough to parse/detect
>
> method (arg1), arg2

Are you talking about the warning you get if you do
method (1, 2, 3)
instead of
method(1, 2, 3)
?

I wonder if this is related to the bracket ambiguity, i.e.

puts (a+b).abs => puts((a+b).abs)
puts(a+b).abs => (puts(a+b)).abs

Neither of these generates a warning (1.8.2p2), but they do different things
depending on whether the space is there or not.

Trying a few combinations with more than one argument:

1. puts (a+b), c works - no warning is generated
2. puts(a+b), c fails
3. puts(a+b, c) works - no warning
4. puts (a+b, c) works - but generates a warning
5. puts (a+b) works - no warning
6. puts(a+b) works - no warning

So I'm not exactly sure why case 4 generates a warning, but case 5 doesn't.
In case 4, the brackets contain a comma, so surely it must be an argument
list, and therefore must be associated with the method name before it?

The example "method (arg1), arg2" seems to be an example of case 1, and that
works just fine under 1.8.2-p2

There is an ambiguity for

foo(bar (a+b), c)

which generates
warning: parenthesize argument(s) for future version

but it seems to resolve it as

foo(bar((a+b),c))

which I suppose is as reasonable a guess as any.

Regards,

Brian.


Yukihiro Matsumoto

11/8/2004 2:21:00 AM

0

Hi,

In message "Re: argument parenths"
on Sat, 6 Nov 2004 22:38:16 +0900, Brian Candler <B.Candler@pobox.com> writes:

|Are you talking about the warning you get if you do
| method (1, 2, 3)
|instead of
| method(1, 2, 3)
|?

Yes.

|Trying a few combinations with more than one argument:
|
|1. puts (a+b), c works - no warning is generated
|2. puts(a+b), c fails
|3. puts(a+b, c) works - no warning
|4. puts (a+b, c) works - but generates a warning
|5. puts (a+b) works - no warning
|6. puts(a+b) works - no warning
|
|So I'm not exactly sure why case 4 generates a warning, but case 5 doesn't.
|In case 4, the brackets contain a comma, so surely it must be an argument
|list, and therefore must be associated with the method name before it?

Hmm, I had extended syntax rules little by little, so that the
argument warning behavior might be inconsistent. I will revisit it
soon.

matz.


SER

11/8/2004 12:16:00 PM

0

On Sunday 07 November 2004 21:20, Yukihiro Matsumoto wrote:
> on Sat, 6 Nov 2004 22:38:16 +0900, Brian Candler <B.Candler@pobox.com>
> writes:
...
> |4. puts (a+b, c) works - but generates a warning
> |5. puts (a+b) works - no warning
...
> |So I'm not exactly sure why case 4 generates a warning, but case 5
> | doesn't. In case 4, the brackets contain a comma, so surely it must be an
> | argument list, and therefore must be associated with the method name
> | before it?
>
> Hmm, I had extended syntax rules little by little, so that the
> argument warning behavior might be inconsistent. I will revisit it
> soon.

While I, personally, wasn't happy with the addition of the warnings, the rules
_are_ consistent, which is nice.

--
### SER
### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Aikido
### http://www.germane-softwar... jabber.com:ser ICQ:83578737
### GPG: http://www.germane-softwar.../Security/ser_public.gpg

Yukihiro Matsumoto

11/8/2004 2:45:00 PM

0

Hi,

In message "Re: argument parenths"
on Mon, 8 Nov 2004 21:16:25 +0900, "Sean E. Russell" <ggg@ser1.net> writes:

|> Hmm, I had extended syntax rules little by little, so that the
|> argument warning behavior might be inconsistent. I will revisit it
|> soon.
|
|While I, personally, wasn't happy with the addition of the warnings, the rules
|_are_ consistent, which is nice.

I'm glad to hear that is consistent. Any opinion would be welcome.

matz.