From: Logan Capaldo Date: 2006-09-25T05:32:54+09:00 Subject: Re: Riddle me this (a question about expressions) On Mon, Sep 25, 2006 at 05:10:18AM +0900, Robert Klemme wrote: > Patrick Toomey wrote: > >I guess that is what surprises me. I would expect return to work > >exactly like raise. > > I on the other hand expect "raise" to work exactly like "return". :-) > > >Someone else gave the example of simplifying my question down to the > >equivalent of trying the following > > > >x = return 9 > > > >Why shouldn't this be valid? > > Because "return" never returns. (Uh, this starts sounding like Zen...) > > > As shown above, raise seems to return nil, > > No, "raise" does neither return nil nor anything else. It does not > return in the same way as "return" never returns. The whole point of > the two is that they do *not* behave like an expression but transfer > control flow up the call stack. > Regardless of whether or not it makes logical sense to say a = return b, I think the confusion is that x = raise b is _not_ a syntax error while x = return b _is_ a syntax error. Frankly, I think this is probably either a) an oversight in the grammar or b) the need to handle the super weird edge case of a = raise 'error' rescue nil Either a = raise b should be a syntax error, or a = return b should not. I'd lean towards the former, if it were up to me. > >and return seems like it should return a similar value if there is no > >other reasonable return value. Just for my own curiosity, what > >implications would returning "nil" have? > > It does not work. Please take the time and meditate about this. > > > Anyway, thanks for all your > >help. I realize most of this is of academic value, but it really helps > >to see how Ruby works underneath. > > In this case I'd rather say, you hit behavior that is common to *all* > programming languages that know "return". But I get the feeling that > you still not fully understood the difference between an arbitrary > expression and a return statement... > > Kind regards > > robert