develooper Front page | perl.perl6.language | Postings from February 2002

Re: proposal: when-blocks, and binding $_

Thread Previous | Thread Next
From:
Austin Hastings
Date:
February 27, 2002 10:11
Subject:
Re: proposal: when-blocks, and binding $_
Message ID:
20020227181113.29869.qmail@web12302.mail.yahoo.com

--- Allison Randal <al@shadowed.net> wrote:
> I'm still not convinced of your basic point, that it would be a good
> thing to have C<when> aliasing $_. Variations on whether it does it
> automatically or at my request and how don't change the fundamental
> concept. C<when> is a conditional like C<if>, not a topicalizer.

Right, it's a topicalizee, the victim of topicalization. And so it uses
$_ or $x or $! or whatever the current topic is.

But inside, you have to KNOW what the topic is again, you can't just
use the default variable(s), so that differentiation of

for @logged_exceptions -> $e {
  when .survivable { if $e.isa('Exception::PEBKAC') { ... } }
}

versus

CATCH {
  when .survivable { if $!.isa('Exception::PEBKAC') { ... } }
}

becomes necessary. 

What I'm trying to suggest is that C<when>, because it already is doing
some special things (huge list of conditionals to try, implied 'next'),
is an orthogonal code element. It really IS going sideways, and unless
you are coding sideways (using C<given> or C<CATCH>) the when-block
represents a context-switch at the developer level.

To that end C<when> should, when (urg!) used in a loop or other
straight-ahead construct to check the current topic, force the current
topic to become the default.

=Austin


__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About