From: Stefan Kaes Date: 2005-11-23T00:58:00+09:00 Subject: Re: semenatics of if/unless/while statement modifiers Yukihiro Matsumoto wrote: >Hi, > >In message "Re: semenatics of if/unless/while statement modifiers" > on Tue, 22 Nov 2005 17:10:32 +0900, Stefan Kaes writes: > >|I perfectly understand your argument. Anyone writing code like this >| >|x = ( >| line1; >| line2; > >| line29; >| line30) if expr >| >|should be shot ;-) although it's legal syntax. >| >|Fact is, noone writes it that way. > >Because you shoot all who write in that way. ;-) > >The current syntax rule is: > > if assignment is done, a right hand side identifier is a local > variable thereafter. > > Just keep it. >And your proposed rule is: > > if assignment is done, a right hand side identifier is a local > variable thereafter. and assignment in modifier condition affects > modifying statement as well. > > There's no need for this rule. See below. >Despite your first impression, it's complex and confusing rule. > > I don't understand why it's confusing. Just state that "expr1 if expr2" has *exactly* the same semantics, both dynamic and static, as "if expr1 then expr2 end", only written in a different way. What could be confusing about that? No special rule required at all. Unless I'm missing something. With this definition, you're left with the implementation problem. But this is entirely separate from semantics definition. >Besides that it doesn't help cases like: > > while true > a > a = 1 > end > > This wouldn't be changed by above rule. It would have the same semantics as "(a; a = 1) while true" ;-) >Only alternative reasonable rule I can think of is: > > if there is assignment, a right hand side identifier is a local > variable in the current scope. > > That would be a possibility. >But it's rather drastic change. I'm not sure if it's a good rule, >or worth the change. > matz. > > No need to make this change. See above. BTW, as far as I know, there is no "official" semantics definition for Ruby. Or do you count the piackaxe book as the definition? -- stefan