From: Caleb Clausen Date: 2006-03-03T04:18:17+09:00 Subject: Re: Subclassing Struct.new On 3/1/06, Yukihiro Matsumoto wrote: > My original intention is _not_ to use local variables before their > first assignment, but to extent their scope to by their outer most > appearance in the method. I'm trying to understand the distinction... I think I see. It's cases where the assignment happens (or might happen?) after a use at runtime, but also, the use comes before the assignment in the lexical order. > But at the same time, I expect the new rule > to solve > > print foo if foo = bar() The perfect example. This, I agree ought to work as expected. I'm not sure I can see an easy way to make it work, but it seems like there might be a special case... on the other hand, maybe just a special case isn't good enough. What about this: until foo && foo.k foo=readfoo end Sort of silly, there's a better way to do this. But the question is, do you want foo to be a variable on the first line? And this case: > | def baz > | n # will be variable > | n = 3 > | n # variable > | end is clearly always use before definition. Should this cause a warning or something then? > I will ponder the new rule (and implementation) bit more. One thought I had: if there isn't a clever trick for inline if, maybe the best way is to keep the existing semantics and issue a warning if there's a method call with a name that subsequently is used for a local variable in the same scope. That shouldn't be too hard.