On Thu, Dec 06, 2007 at 04:36:26PM -0800, Jonathan Lang wrote:
: Larry Wall wrote:
: > On Tue, Dec 04, 2007 at 08:40:10AM -0800, Jonathan Lang wrote:
: > : or (I think):
: > :
: > :   method test ($value) {
: > :     setup();
: > :     when $value { doit() } #[smart-match the calling object $_ against 
$value.]
: > :   }
: >
: > I know it used to be that way back near the Dawn of Time, but methods
: > don't automatically topicalize anymore unless you explicitly name
: > one of the parameters '$_':
: 
: Huh.  I guess I need to review current standards for method
: declaration; last I'd checked, the invocant did not need to be
: explicitly named.

It doesn't.  But explicitly giving it the name $_ requires that you
explicitly name it.

: > : (Question: assuming that the above is valid, would breaking out of the
: > : when block be the same as returning from the method?  Or would it
: > : qualify as an abnormal termination of the method?)
: >
: > Well, according to S04:
: >
: >     "If the smart match succeeds, C<when>'s associated block is
: >     executed, and the innermost surrounding block that has C<$_>
: >     as one of its formal parameters (either explicit or implicit)
: >     is automatically broken out of."
: 
: ...which didn't answer my question, since "returning from the method"
: and "having the method die" both qualify as breaking out of the method
: in my mind.

Given that this is describing the ordinary break behavior of ordinary switch
statements, and there is a long C tradition of using the term "break"
for a simple goto to the end of a switch, I think you're reading it a
little sideways from how most people will.  Nevertheless...

: > So it merely returns normally from the method, which is what you'd
: > generally expect.
: 
: This makes sense to me.  Perhaps S04 could be updated to make this a
: bit more explicit?  Also, can 'break' take a parameter?  My gut
: instinct is "no"; if you want to break out of a method while
: specifying a return value, you should probably use 'return' instead of
: 'break'.  Indeed, you may want to make this mandatory, much like the
: conjecture about forcing people to use 'next' or 'last' instead of
: 'break' when in a loop.

I will attempt to clarify.  I've also tried to unify the syntax of
all the loop and switch exits with ".leave" so they all can be of
the form LABEL.oops($retval).   That means that next, last, and break
can now optionally specify return values.

Larry

Reply via email to