<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=""><div class="">That's right. Swift's operators are whitespace-sensitive. The rules are:</div><div class="">* Whitespace on both sides: infix operator</div><div class="">* Whitespace on neither side: infix operator</div><div class="">* Whitespace on only one side: prefix or postfix operator</div><div class=""><br class=""></div><div class="">Therefore the expression `i =3` uses prefix operator = . There is no such operator, and it's reserved so you can't write your own.</div><div class="">`i = 3` and `i=3` and `i = &nbsp; &nbsp; 3` are both the ordinary infix operator = .</div><div class=""><br class=""></div><div class="">Obligatory open-source opportunity: add a compiler fix-it for this. (Perhaps just the prefix/postfix = case specifically, perhaps the more general case where the requested operator does not exist but an operator with different fixity does.)</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 8, 2016, at 10:54 PM, Jo Albright via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Zhaoliang,<div class=""><br class=""></div><div class="">Try adding a space between the “=“ &amp; “3”&nbsp;</div><div class=""><br class=""></div><div class="">var i = 3</div><div class=""><br class=""></div><div class="">instead of</div><div class=""><br class=""></div><div class="">var i =3</div><div class=""><br class=""></div><div class="">That should fix the issue.</div><div class=""><br class=""></div><div class="">The second way makes it think you are trying to use it as a prefix operator instead of an assignment.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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; float: none; display: inline !important;" class=""><font color="#8d8d8d" class=""><span class="Apple-converted-space">&nbsp;</span>Nerd . Designer . Developer</font></span><font color="#464646" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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; float: none; display: inline !important;" class="">Jo Albright</span></font><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class="">
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 9, 2016, at 12:07 AM, zhaoliang via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">hello ,<div class="">&nbsp; &nbsp; I find a bug like this:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;&nbsp;<span style="font-family: Menlo; font-size: 11px;" class="">zhaoliangdeMacBook-Pro:~ zhaoliang$ swift</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #a9a9a9" class="">&nbsp; 1&gt; </span>var i =3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><b class="">repl.swift:1:7: </b><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class=""><b class="">error: </b></span><b class="">prefix '=' is reserved</b></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">var i =3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 189, 38);" class=""><b class="">&nbsp; &nbsp; &nbsp; ^</b></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #a9a9a9" class="">&nbsp; 1&gt; </span>var i=3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 187, 199);" class="">i: Int = 3</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(169, 169, 169);" class="">&nbsp; 2&gt; <span style="" class="">&nbsp;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(169, 169, 169);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp;</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZKcnqA3HtCYQN0SS0ldgu-2FKfSA7a4n0D-2FcEq84jeql9yvafrKWFd9CP97RpHhvPE-2BmwMLxYwfk3tO-2FlbpVFS4uCZoo8Cd7WoPA40LGw-2BScGCqhwGxYSlniqzWw3jOo6fBi5ys7hciCtM7qSrZdgUipcRHDlK9rTvjHi8myo62Kw86Ig00eDGDUHJQeRZL7Te-2BMPZ-2Fefp-2FfctARBJ1D-2B9uQ-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></div></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=63dpwJVPeughRPVVcLGXjDCURLYJIqqpP6u0-2FFoBCFgJmWLwLwofHrs-2FD6x-2BrowM9ZAdKgdZq62-2Bvl-2BxGraKXwA2arw10RzPDUqzLKsvdHDAFf588sqyovKAPjRF4Ca37-2BByeutqHJcVf9atFcmMs82E0Mh7wHJWncn-2Bfv7EitUUeunqv0g7bcvQv9HJ9C2QG5Hj36SCt2X2GeKxLSc09dnMP-2BkppxSHgVApGqffh5g-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></body></html>