[swift-users] Associativity of && and || operator
Howard Lovatt
howard.lovatt at gmail.com
Mon Feb 20 16:09:13 CST 2017
To me it would be surprising if && grouped differently than * or &; since
it is closely associated with boolean-and, which in turn is the equivalent
operation to multiply in Boolean logic.
On Fri, 17 Feb 2017 at 7:56 pm, rintaro ishizaki via swift-users <
swift-users at swift.org> wrote:
> Hello all,
>
> Why the associativity of Logical{Conjunction,Disjunction}Precedence is "
> left"?
>
> If you write: A && B && C, it's grouped as (A && B) && C.
> This means that the && function is *always* called twice: (&&)((&&)(A,
> B), C).
> I feel "right" associativity is more natural: (&&)(A, (&&)(B, C)),
> because the && function is called only once if A is false.
>
> I know that redundant && calls are optimized away in most cases.
> I also know C and C++ standard says: "The && operator groups
> left-to-right", and most programming languages follow that.
>
> But why not "right" associativity?
> What is the difference between logical operators and ?? operator that has
> "right" associativity?
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
--
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170220/ab9a342c/attachment.html>
More information about the swift-users
mailing list