From: Gary Wright Date: 2011-12-18T10:20:22+09:00 Subject: [ruby-core:41709] Re: Documentation of the language itself (syntax, meanings, etc) --Apple-Mail=_395B0408-E86A-4A50-B28A-A113D2E948D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On Dec 17, 2011, at 7:15 AM, Rodrigo Rosenfeld Rosas wrote: > Great! I didn't know about this. But the information about return = doesn't seem to be accurate: >=20 > "Inside a code block, the behavior of return depends on whether or not = the block constitutes the body of a regular Proc object or a = lambda-style Proc object. In the case of a lambda, return causes = execution of the block to terminate. In the case of a regular Proc, = return attempts to return from the enclosing method. If there is no = enclosing method, it=92s an error." >=20 > What is the meaning of "enclosing" in this context? >=20 > def method_name(proc_argument) > proc_argument[] # contains a return > end >=20 > My understanding is that the enclosing method of the proc call is = "method_name". No. Enclosing means the method that lexically encloses the block (and = thus the 'return') where it appears in the source. > Even if you say the the definition for "enclosing method" is the one = that defined the proc, it still exists, so the snippet "If there is no = enclosing method, it's an error." also doesn't reflect the situation. There are several cases where there might not be a lexically enclosing = method: - a proc defined at the top level - a proc defined within a module or class block but not within a method = definition Basically you shouldn't be creating procs in these places but lambdas = instead. It is also possible that there is no occurrence of the method on the = call stack when the block is called and the return executed. That is to say that the = enclosing method has already returned when the block is called. > The definition of return for procs should be clearer IMO in the docs = above, don't you agree? Yep, the documentation could be clearer. Gary Wright= --Apple-Mail=_395B0408-E86A-4A50-B28A-A113D2E948D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252
=20 =20
Great! I didn't know about = this. But the information about return doesn't seem to be accurate:

"Inside a code block, the behavior of return depends on whether or not the block constitutes the body of a regular Proc object or a lambda-style Proc object. In the case of a lambda, return causes execution of the block to terminate. In the case of a regular Proc, return attempts to return from the enclosing method. If there is no enclosing method, it=92s an error."

What is the meaning of "enclosing" in this context?

def method_name(proc_argument)
    proc_argument[] # contains a return
end

My understanding is that the enclosing method of the proc call is "method_name".

No. =  Enclosing means the method that lexically encloses the block (and = thus the 'return') where it appears in the source.

Even if you say = the the definition for "enclosing method" is the one that defined the proc, it still exists, so the snippet "If there is no enclosing method, it's an error." also doesn't reflect the = situation.

There are several = cases where there might not be a lexically enclosing method:
- = a proc defined at the top level
- a proc defined within a = module or class block but not within a method = definition

Basically you shouldn't be creating = procs in these places but lambdas instead.

It = is also possible that there is no occurrence of the method on the call = stack when the
block is called and the return executed. =  That is to say that  the enclosing method
has = already returned when the block is called.

The definition = of return for procs should be clearer IMO in the docs above, don't you agree?

Yep, = the documentation could be clearer.

Gary = Wright
= --Apple-Mail=_395B0408-E86A-4A50-B28A-A113D2E948D4--