On 9/25/06, Rick DeNatale <rick.denatale / gmail.com> wrote:
> Regardless of what happens under the covers with setjmp/longjmp, I
> can't see anyway to explain the results syntactically other than
> saying that the 'raise .. rescue ...' is an rvalue in the assigment.
>
> The genesis of this thread was why the ruby compiler disallows:
>
>      x = return y
>
> but allows
>
>      x = raise rescue 1
>
> And some have expressed the opinion that both should be disallowed.
>
> I can't agree. 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

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]. This makes much more sense as one could imagine an invisble
wrapper like:

@x = begin raise rescue 42 end

So should raise w/o the rescue be illegal? (no begin/end semantically)

> Of course the final arbiter is Matz.

Agreed. I personally think that this is a rather unimportant corner
case. I'm not sure I would change anything myself.

Brian.

[1] Note that:

x = begin
  raise
resue
  42
end

p x #=> 42