Hi --

On Mon, 25 Sep 2006, Hal Fulton wrote:

>>> 
>>> 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.
>>> 
>
> Nevertheless I think it's significant that raise is a method
> whereas return (of course) is not.

I think so too.  I would not want to see a method call of any kind be
dealt with as a syntax error just because it has an assignment to its
left.  Since return can't really be a method (at least my brain can't
wrap itself around that concept :-) I don't think that the two of them
need to be thought of together with regard to the syntax-error matter.

> I wonder if there is some case where raise would/does return
> a meaningful value somehow? My gut reaction is 'no'... but
> this is Ruby...

I am fairly certain that the return value can never be captured.  At
least I can't figure out how to do it.

In this:

  def raise_value
    x = raise
  rescue
    x
  end

  p raise_value   # nil

I'm pretty sure that x is nil because of the thing where the parser
sees an assignment and defines the variable.  I don't think an
assignment ever actually takes place -- as witness the fact that:

   x = raise || 1

also leaves x as nil.


David

-- 
                   David A. Black | dblack / wobblini.net
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org