In a message dated Sun, 8 Sep 2002, Steve Canfield writes:
> Would it be accurate to say that "is" sets properties of variables, whereas
> "but" sets properties of values? If so, what would this output:
>
> my $var is true;
> $var=0;
> if ($var) {print "true"}
> else {print "false"}
>
> I would expect it to output "false".
Why? I believe that, whatever you set $var to, you have marked the
variable as constantly true in booleans.
Where this gets weird is that someone might write:
sub foo {
my $result is true;
# (do stuff setting result)
if $success {
return $result;
} else {
return undef;
}
}
Thinking that the initial "is true" will cause the test
if foo() ....
will always be true if the sub succeeded, even if $result was zero. But I
don't think that's how it works, since the C<return> will pass the
*value*, which has not been tagged with "but true", not the variable,
which has been tagged with "is true". So the test will fail when $result
was zero. (Unless there's something going on where the "is true" property
confers a property to the value, which I suppose is possible, but weird.)
My guess is that
return $foo but true;
will become a common piece of Perl 6 idiom.
Trey