David Mertens wrote:
On Thu, Jul 6, 2017 at 11:05 PM, <[email protected] <mailto:[email protected]>> wrote:Perl is highly unusual in that the operator, not the operand, dictates the context. Good point - and one that I hadn't got around to noticing. Therefore, the '!' operator has to be set up to either: a) operate always in numeric context; or b) operate always in string context; or c) operate always in both contexts (as per the current behaviour). Having an ambivalent '!' operator (where it alternates between a) and b), according to the operand's flags) is therefore not an option. If we wanted an operator for "logical string negation" and an operator for "logical numeric negation" we would need 2 different operators. Have I got that somewhere near right ? Cheers, Rob Yes, I think so. Of course, that was one of Larry's design decisions, and I think it was a good one. If you really care to have operand-dependent behavior, you can create a class that overloads the operator and carry your data around in instances of that class. Also, boolean works beyond simple string and numeric context. In particular, boolean context coerces undefined values to false without issuing warnings, and it's not clear how an undefined value would operate under "logical string negation" and "logical numeric negation".
It is nonsense to logically negate a string, and it is nonsense to convert undefined values into 'false'. Either are neither false, nor true. For undefined values, there is no way of deciding whether they are true or false because they are undefined. When you convert undefined values to false, then you must also convert false to undefined values. Logic dictates that otherwise undefined values are not equal to undefined values. Yet perl claims that they are: perl -e 'print "true\n" if(undef == undef);' perl -e 'print "true\n" if(0 == undef);' Both is just wrong. The value 0 is defined to the point where you can´t define it any more. -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
