<Removed perl6-announce x-post>

Tom Christiansen wrote:
> Hm....  I don't recall C++ ever thinking to overload the control-flow
> operators ("&&", "||", "," (that is, comma), and "?:").   Why not?
> Even if their "a && b" should produce a more mundane 1 or 0, one
> still might wish control.
>
'&&', '||', et al are just operators that happen to evaluate their second
argument lazily. There's no reason to assume that the prototype to _any_
operator couldn't specify one or more lazily evaluated arguments in Perl 6.
I don't see why we should assume that these four operators should be the
only operators to provide this control-flow side-effect.

> <...>
> I do not see how it is a
> feature to create a new universe in which
>
>     !a && !b
> and
>      a ||  b
>
> can no longer equated.

It's always dangerous to make assumptions about what rules an operator
obeys. As well as the various logical operator equalities, there's

  a + b == b + a

and

  a + (b + c) == (a + b) + c

and so forth.

Which of these equalities holds for which operators for which types should
not necessarily be assumed. It's nice to be able to implement non-standard
logic by overloading standard operators, and to work with tensors, complex
numbers, non-cartesian coordinate systems and so forth where not all
'standard' rules (rational numbers; cartesian coordinates; classical logic;
...) necessarily apply.

Is the key issue here about what optimisations Perl can make? If so, we
should look to enumerate the properties of an operator under which specific
optimisations can be made. Then we can check the prototype of an overloaded
operator to see if it fits these properties, and maybe add attributes (e.g.
':associative') where the prototype does not provide sufficient information.


Reply via email to