<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Left associativity is most likely just a holdover from the C family–not conforming with it would break expectations for programmers coming from these languages. And as you mentioned, the compiler will short-circuit the condition and stop evaluating as soon as it encounters a false condition, so there’s no measurable benefit.<div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 17, 2017, at 12:54 AM, rintaro ishizaki via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hello all,</div><div class=""><br class=""></div><div class="">Why the associativity of <font face="monospace, monospace" class="">Logical{Conjunction,Disjunction}Precedence</font> is "<font face="monospace, monospace" class="">left</font>"?<br class=""></div><div class=""><br class=""></div><div class="">If you write: <font face="monospace, monospace" class="">A && B && C</font>, it's grouped as <font face="monospace, monospace" class="">(A && B) && C</font>.</div><div class="">This means that the<font face="monospace, monospace" class=""> &&</font> function is <i class="">always</i> called twice: <font face="monospace, monospace" class="">(&&)((&&)(A, B), C)</font>.</div><div class="">I feel "right" associativity is more natural: <span style="font-family:monospace,monospace" class="">(&&)(A</span><span style="font-family:monospace,monospace" class="">, (&&)(B, C))</span><font face="arial, helvetica, sans-serif" class="">,</font><br class=""></div><div class=""><font face="arial, helvetica, sans-serif" class="">because the </font><font face="monospace, monospace" class="">&&</font><font face="arial, helvetica, sans-serif" class=""> function is called only once if </font><font face="monospace, monospace" class="">A</font><font face="arial, helvetica, sans-serif" class=""> is </font><font face="monospace, monospace" class="">false</font><font face="arial, helvetica, sans-serif" class="">.</font></div><div class=""><br class=""></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">I know that redundant && calls are optimized away in most cases.</span><br class=""></div><div class=""><div class=""><font face="arial, helvetica, sans-serif" class="">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=""><br class=""></div><div class=""><font face="arial, helvetica, sans-serif" class="">But why not "</font><font face="monospace, monospace" class="">right</font><font face="arial, helvetica, sans-serif" class="">" </font>associativity<span style="font-family:arial,helvetica,sans-serif" class="">?</span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">What is the difference between logical operators and </span><font face="monospace, monospace" class="">??</font><font face="arial, helvetica, sans-serif" class=""> operator that has "</font><font face="monospace, monospace" class="">right</font><font face="arial, helvetica, sans-serif" class="">" associativity?</font></div><div class=""><br class=""></div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>