<div dir="ltr">Well you cannot define it because the \ character itself is not allowed outside of a string.<div>If you try to declare it with</div><div><br></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">infix </span><span style="font-variant-ligatures:no-common-ligatures">operator</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> \</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><br></span></p><p style="margin:0px;line-height:normal"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small">you get an error </span>&quot;Invalid character in source file&quot; in Xcode and where you define the function itself you have the same error.<br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><br></span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small">This would not happen if it was part of the allowed operator-head characters. Here is the grammar of operator for Swift 3.0.1 (from </span></span><span style="font-family:arial,sans-serif;font-size:small;color:rgb(34,34,34)"><a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/zzSummaryOfTheGrammar.html">https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/zzSummaryOfTheGrammar.html</a> )</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><br></span></span></p>GRAMMAR OF OPERATORS<br>operator → operator-head­operator-characters­opt­<br>operator → dot-operator-head­dot-operator-characters­<br><br></div><div>operator-head → /­  =­  -­  +­  !­  *­  %­  &lt;­  &gt;­  &amp;­  |­  ^­  ~­  ?­<br>operator-head → U+00A1–U+00A7<br>operator-head → U+00A9 or U+00AB<br>operator-head → U+00AC or U+00AE<br>operator-head → U+00B0–U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7<br>operator-head → U+2016–U+2017 or U+2020–U+2027<br>operator-head → U+2030–U+203E<br>operator-head → U+2041–U+2053<br>operator-head → U+2055–U+205E<br>operator-head → U+2190–U+23FF<br>operator-head → U+2500–U+2775<br>operator-head → U+2794–U+2BFF<br>operator-head → U+2E00–U+2E7F<br>operator-head → U+3001–U+3003<br>operator-head → U+3008–U+3030<br><br></div><div>operator-character → operator-head­<br>operator-character → U+0300–U+036F<br>operator-character → U+1DC0–U+1DFF<br>operator-character → U+20D0–U+20FF<br>operator-character → U+FE00–U+FE0F<br>operator-character → U+FE20–U+FE2F<br>operator-character → U+E0100–U+E01EF<br>operator-characters → operator-character­operator-characters­opt­<br><br>dot-operator-head → .­<br>dot-operator-character → .­  operator-character­<br>dot-operator-characters → dot-operator-character­dot-operator-characters­opt­<br><br>binary-operator → operator­<br>prefix-operator → operator­<br>postfix-operator → operator­</div><div><br></div><div><br></div><div>The change I propose would basically lead to have</div><div>operator-head → /­  =­  -­  +­  !­  *­  %­  &lt;­  &gt;­  &amp;­  |­  ^­  ~­  ?­ \<br></div><div><br></div><div>instead of the line </div><div><br></div><div>operator-head → /­  =­  -­  +­  !­  *­  %­  &lt;­  &gt;­  &amp;­  |­  ^­  ~­  ?­<br></div><div><br></div><div>in the swift grammar.<br></div><div><br></div><div><br></div><div>Nicolas<br><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"></span></p><section class="gmail-section" style="padding:15px 25px 30px"><a name="//apple_ref/doc/uid/TP40014097-CH38-ID482" style="background-color:transparent;border:0px;font-size:10px;outline:0px;padding:85px 0px 0px;vertical-align:baseline;display:block;width:0px;height:0px;color:rgb(0,136,204);font-family:helvetica,arial,sans-serif"></a></section><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><br></span></span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><br></span></span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><br></span></span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"> wi</span><br></span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 5, 2017 at 4:55 PM, Derrick Ho <span dir="ltr">&lt;<a href="mailto:wh1pch81n@gmail.com" target="_blank">wh1pch81n@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If the \ operator is not defined in swift, does it treat it as something that can be operator overloaded?<br><br><br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Sun, Feb 5, 2017 at 10:29 AM Nicolas Fezans via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr" class="m_-2886518073382278604gmail_msg">Dear all,<div class="m_-2886518073382278604gmail_msg"><br class="m_-2886518073382278604gmail_msg"></div><div class="m_-2886518073382278604gmail_msg">This is a rather simple proposal to add &#39;\&#39; (backslash character) as a valid operator-head in the swift grammar.</div><div class="m_-2886518073382278604gmail_msg"><br class="m_-2886518073382278604gmail_msg"></div><div class="m_-2886518073382278604gmail_msg">One argument for it, is that there exist a backslash operator in the MATLAB/Scilab/Octave languages. In this languages A\B solves the linear system A*X = B for X (or the least square problem associated to it if the system of equations is overdetermined). I am doing some numerical computation in Swift and it would be nice to be able to declare the same operator name for this functionality.</div><div class="m_-2886518073382278604gmail_msg"><br class="m_-2886518073382278604gmail_msg"></div><div class="m_-2886518073382278604gmail_msg">I might have missed some arguments for not adding them, but I seems to me that until now the \ character is only used inside of string literals. If that is the case, both uses should never generate a conflict or be ambiguous, isn&#39;t it? (String literals keep their interpretation of \ and \ used otherwise within the swift code will be interpreted as an operator or as the beginning of an operator)</div><div class="m_-2886518073382278604gmail_msg"><br class="m_-2886518073382278604gmail_msg"></div><div class="m_-2886518073382278604gmail_msg">I am curious to see what will be the feedback on this.</div><div class="m_-2886518073382278604gmail_msg"><br class="m_-2886518073382278604gmail_msg"></div><div class="m_-2886518073382278604gmail_msg">Nicolas</div></div></div></div>
______________________________<wbr>_________________<br class="m_-2886518073382278604gmail_msg">
swift-evolution mailing list<br class="m_-2886518073382278604gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="m_-2886518073382278604gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_-2886518073382278604gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_-2886518073382278604gmail_msg" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br class="m_-2886518073382278604gmail_msg">
</blockquote></div>
</blockquote></div><br></div>