<div>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. </div><div><br><div class="gmail_quote"><div>On Fri, 17 Feb 2017 at 7:56 pm, rintaro ishizaki via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><div class="gmail_msg">Hello all,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Why the associativity of <font face="monospace, monospace" class="gmail_msg">Logical{Conjunction,Disjunction}Precedence</font> is "<font face="monospace, monospace" class="gmail_msg">left</font>"?<br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">If you write: <font face="monospace, monospace" class="gmail_msg">A && B && C</font>, it's grouped as <font face="monospace, monospace" class="gmail_msg">(A && B) && C</font>.</div><div class="gmail_msg">This means that the<font face="monospace, monospace" class="gmail_msg"> &&</font> function is <i class="gmail_msg">always</i> called twice: <font face="monospace, monospace" class="gmail_msg">(&&)((&&)(A, B), C)</font>.</div><div class="gmail_msg">I feel "right" associativity is more natural: <span style="font-family:monospace,monospace" class="gmail_msg">(&&)(A</span><span style="font-family:monospace,monospace" class="gmail_msg">, (&&)(B, C))</span><font face="arial, helvetica, sans-serif" class="gmail_msg">,</font><br class="gmail_msg"></div><div class="gmail_msg"><font face="arial, helvetica, sans-serif" class="gmail_msg">because the </font><font face="monospace, monospace" class="gmail_msg">&&</font><font face="arial, helvetica, sans-serif" class="gmail_msg"> function is called only once if </font><font face="monospace, monospace" class="gmail_msg">A</font><font face="arial, helvetica, sans-serif" class="gmail_msg"> is </font><font face="monospace, monospace" class="gmail_msg">false</font><font face="arial, helvetica, sans-serif" class="gmail_msg">.</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><span style="font-family:arial,helvetica,sans-serif" class="gmail_msg">I know that redundant && calls are optimized away in most cases.</span><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><font face="arial, helvetica, sans-serif" class="gmail_msg">I also know C and C++ standard says: "The && operator groups left-to-right", and most programming languages follow that.</font></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="arial, helvetica, sans-serif" class="gmail_msg">But why not "</font><font face="monospace, monospace" class="gmail_msg">right</font><font face="arial, helvetica, sans-serif" class="gmail_msg">" </font>associativity<span style="font-family:arial,helvetica,sans-serif" class="gmail_msg">?</span></div><div class="gmail_msg"><span style="font-family:arial,helvetica,sans-serif" class="gmail_msg">What is the difference between logical operators and </span><font face="monospace, monospace" class="gmail_msg">??</font><font face="arial, helvetica, sans-serif" class="gmail_msg"> operator that has "</font><font face="monospace, monospace" class="gmail_msg">right</font><font face="arial, helvetica, sans-serif" class="gmail_msg">" associativity?</font></div><div class="gmail_msg"><br class="gmail_msg"></div></div>
_______________________________________________<br class="gmail_msg">
swift-users mailing list<br class="gmail_msg">
<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">-- Howard.</div>