From: Allison Randal [mailto:[EMAIL PROTECTED]]
> On Wed, Feb 27, 2002 at 04:24:48PM -0600, Garrett Goebel wrote:
> > From: Allison Randal
> > 
> > Not just some value external to the switch, but the value in $_.
> > 
> > I now see the DWIM aspect. Thanks BTW.
> > 
> > But how often will people have non- C<when> statements 
> > within a C<given> scope that'll need the special case
> > handling so they can see a different $_ than C<when>?
> 
> That's exactly what the non- C<when> statements will see currently.

Yes, I understand why that would be DWIMish. But is it going to be used
enough to justify the seeming inconsistency with the "$_ is _the_ default
variable" concept that Perl5 uses and Perl6 uses consistently outside
given/when. Topicalizers add a layer of complexity to the things that won't
be staring you in the face when you look at the code.

I'm neither a language guru nor designer, so I defer to the greater wisdom.
I do worry that as Perl grows richer, so does the need for underlying
consistency and simplicity. I guess it is all about seeking the correct
balance. And that is something Larry and the Perl community have a pretty
good track record with so far.


> Are you asking the question in the context of Apocalypse 4 or in the
> context of the hypothetical "C<when> aliases to $_" discussion? I'll
> answer as if the former, because it seems to fit the best, but if you
> meant the latter the answer would be slightly different.

Scanning the "C<when> aliases to $_" discussion provoked me to go back and
reread Apocalypse 4. So I'd have to say Apoc4

 
> I think we're bogged down in the "$_ is default" idea. We really have
> two entirely separate defaults, $_ and topic. Sometimes they're the
> same and sometimes they're not.

And until now I was safe assuming the one fixed variable $_ as the default.
Now there is the one special case C<when> where I need to know the
difference. And nothing visible in the code to remind me that its there.
Difficult to teach, yet another thing to remember, and a potential nuisance
to debug. Though I guess I'm getting an inkling of how a year from now it'll
be yet another tool who's usefulness I'll take for granted.


> Hmmmmm... pretend for a moment that there's a
> variable $topic (there isn't, but pretend). It's very
> similar to $_, but not quite. When you do a
> 
>       given $x {
>               ...
>       }
> 
> then both $_ and $topic hold the value of $x. But, when you do a
> 
>       given $x -> $y {
>               ...
>       }
> 
> $topic holds the value of $y (i.e. the value of $x), but $_ 
> doesn't (it hasn't been affected at all). 
> 
> C<when> always defaults to $topic, it doesn't care about $_ 
> (except that when $topic has no value at all, it will
> "steal" a value from $_).

Really? I missed that. But yes, there it is:

Larry Wall in Apocalypse 4 writes:
> Outside the scope of any topicalizer, a when will assume that
> its given was stored in $_ and will test implicitly against
> that variable. 

I wonder if this:

for 'foo' {
  given 'food' -> $x {
    print when /$_/
  }
}

would print "food"?

And makes me wonder if:

for 'foo' {
  given 'food' -> {
    print when /$_/
  }
}

Wouldn't be a useful syntax for specifying that the switch value can only be
seen by the case value? I.e. No don't inject 'food' as a lexical, and don't
associate it with the fixed default variable $_ either...


> I think your more general question boils down to: "Is this 
> whole notion of topic really worth the effort"? And the
> confusion about C<when> actually supports your argument.
> Perl gurus and newbies alike are going to have to do a
> little mental stretching for this one (just a tiny bit).
>
> But I do think it's worth it. Despite the details of consistency and
> clarity that still need to be worked out, it's a very dwim change that
> is a big part of the elegance of the switch statement.

Exactly. And thanks to multiple readings of Apocalypse 4, and your
explanations... I'm pretty sure I'm getting it. I might even be a little
more comfortable with it. 

I certainly hope the idea of the topic, topicalizers, and topicalizees as
separate from the fixed $_ default variable gets pounded out quite throughly
in the "What's New?" section of the Perl6 documentation. 

Reply via email to