From: Brian Mitchell Date: 2006-09-26T08:48:35+09:00 Subject: Re: Riddle me this (a question about expressions) On 9/25/06, Rick DeNatale wrote: > On 9/25/06, Brian Mitchell wrote: > > On 9/25/06, Rick DeNatale wrote: > >> I think that the proper documentation of > > > Kernel#raise/Thread#raise should be that it causes a non-local return > > > unless it is rescued, in which case the value is the value of the > > > expression in the rescue. That's how it works now. > > > > Well, those words are sort of confusing: > > > > begin > > @x = raise > > rescue > > 42 > > end > > > > p @x #=> nil > > > > @x = raise rescue 42 > > > > p @x #=> 42 > > No it's the same thing. The value of the lvalue in this case is the > value of raise, which since the raise was rescued is 42. > > I think that my proposed documentation covers this case. > No it doesn't. I would say that is was rescued in my example as well. The language might look like: Kernel#raise/Thread#raise causes a non-local return unless it is rescued, in which case the result _of the begin..end block_ is the result of the expression in the rescue clause. > > To put the result into better perspective, the binding of = is to the > > entire expression including the rescue, which has the result of 42 > > [1]. > > Except in this case the only 'entire expression' which includes the rescue is: > > begin; x=raise;rescue; 42;end > > And x is not being assigned the value of this expression. > Actually, single line rescue has tighter bindings than =. So it would be like I show. x = raise rescue 42 becomes: x = (raise rescue 42) > >This makes much more sense as one could imagine an invisble > > wrapper like: > > > > @x = begin raise rescue 42 end > > But I think it makes even more sense to explain the syntax as it is > rather than modifying it. > That was my attempt. I am explaining that: x = raise "something" rescue 42 has the same result as: x = begin raise "something" rescue 42 end This dispelling any doubt about what other differences might be. We could safely use such a mechanism mentally if it happened to help us. > > So should raise w/o the rescue be illegal? (no begin/end semantically) > > Too fussy, I think. > I'm not sure what you mean here. I am trying to say that it is overly complex to think of raise as an expression which returns. It's kind of like trying to get the result of calling a continuation; it doesn't return one. It is much easier to use a structured interpretation where there are begin..end clauses which happen to behave very dependably. Brian.