On Thu, Jul 6, 2017 at 11:05 PM, <sisyph...@optusnet.com.au> 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".

David

-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

Reply via email to