On Thu, 2002-02-21 at 09:01, Sam Vilain wrote:
> On Thu, 21 Feb 2002 06:50:13 -0600
> [EMAIL PROTECTED] wrote:
>
> > On Thu, Feb 21, 2002 at 12:30:11PM +0000, Sam Vilain wrote:
> > > I think Perl 6 should have a "but" keyword, as in:
> > > if (defined $foo but $foo eq "") {
> > *scratches head*
> > so... it negates the left side, then ANDs it with the right?
>
> No, "but" is syntactically equivalent to "and" in English. It just
> implies that the second condition is not generally what you'd expect if
> the first was true.
>
> Complete syntactic sugar :)
An off-the-wall thought... If this is not the "expected" condition,
should it have the extra meaning of an assertion? For example,
defined $foo but $foo eq ""
could set $! to 'defined $foo but $foo eq ""' and, if -w was in use,
issue 'warn "Exceptional condition: $!"'
Perhaps "but" introduces more information than you had thought....
Is there a unary "but"? Or would that be "never"?
Alternatively, this could all be replaced by "should":
defined $foo && $foo should ne ""
$foo should == $bar
should $state
should not $state
It's not a hard assertion, just a debugging tool.
"should", unlike "but" would probably always force the expression to be
true. So, 'defined $foo && $foo should ne ""' would always be true if
$foo was defined (should "should" become false or die, under "use
strict" or the debugger?)
A stanalone "should not" would be useful for unexpected circumstances
that are not important enough to always issue a warning:
exec($prog);
should not;
This brings up the switch idea... (in C terminology because I don't have
time to look up the Perl version right now):
switch ($x) {
case 1: break;
case 2: break;
default: should not;
}
Ok, I think I'm rambling now... off to do more work.