<div dir="ltr"><div><span style="font-weight:bold;white-space:nowrap;line-height:1.5">Félix Cloutier</span><span style="line-height:1.5"><b>: </b>Yes immutable structures would look just like read-only classes, but I don&#39;t think this makes the choice more ambiguous. The use of structures could be encouraged whenever possible with a clear message: &quot;Is it all immutable? Use structures then&quot;. Perhaps even be explicit on the performance implications of stack storage. I believe the real problem is C interop, and for that I have no arguments.</span><br></div><div><span style="line-height:1.5"><br></span></div><div><span style="font-weight:bold;white-space:nowrap;line-height:1.5">Paul Cantrell: </span>Sure, example below. Changing `struct Position` into `class Position` would still compile and print 30 instead. <span style="line-height:1.5"><br></span></div><div><div><div><br></div><div>======<span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><br></div><div><div>struct Position {</div><div>  var x: Int</div><div>  var y: Int</div><div>  </div><div>  init(x: Int, y: Int) {</div><div>    self.x = x</div><div>    self.y = y</div><div>  }</div><div>}</div><div><br></div><div>func move(var position: Position) {</div><div>  position.x += 20</div><div>}</div><div><br></div><div>var p1 = Position(x: 10, y: 10)</div><div>move(p1)</div><div><br></div><div>print(p1.x) // prints 10</div></div><div>======<span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><span style="line-height:1.5">======</span><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 23, 2015 at 11:24 AM Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com">cantrell@pobox.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Structs behave _as if_ they are immutable and every mutation creates a copy.</div><div><br></div><div>The compiler may — and usually does — optimize this away as a direct mutation. (And then there’s inout, which is tricky.)</div><div><br></div><div>It’s a brilliant model, and I believe a strong one as it stands. Lino, I believe this addresses your #1 and #3. I’m afraid I don’t follow your #2. Can you elaborate?</div><div><br></div><div>Cheers, P</div></div><div style="word-wrap:break-word"><div><br></div><br><div><blockquote type="cite"><div>On Dec 23, 2015, at 10:15 AM, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">No, this is a consequence of structures being passed by value to property accessors. The getter doesn&#39;t return a reference to the frame, it returns a copy of it, so it is accompanied by a hidden set operation where it replaces the whole thing.</div><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;font-family:&#39;Lucida Grande&#39;;line-height:normal;border-spacing:0px">Félix</span></div><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div>Le 23 déc. 2015 à 11:09:43, Kevin Lundberg via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I believe Ian is correct in that changing any struct&#39;s value in any way creates a whole new struct.</span><div style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">See <a href="http://swiftstub.com/635749345" target="_blank">http://swiftstub.com/635749345</a><span> </span>for proof (the didSet property observer fires every time a change happens to the struct).</div><div style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><div><blockquote type="cite"><div>On Dec 23, 2015, at 11:00 AM, Lino Rosa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Reassigning structures will create new ones. Mutating functions and reassigning its properties won&#39;t: they mutate it.<br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 23, 2015 at 10:51 AM Ian Ynda-Hummel &lt;<a href="mailto:ianynda@gmail.com" target="_blank">ianynda@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I thought structures were immutable and mutating functions actually just created new structures, thus maintaining the by value semantics.<br><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr">On Wed, Dec 23, 2015 at 10:45 AM Lino Rosa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>I believe the language would be improved by making structures immutable.</div><div><br></div><div>1) The choice between classes and structures isn’t clear right now. If structures were immutable it would be natural to use them as value objects.</div><div><br></div><div>2) Refactoring a mutable structure into a class when it’s being passed around multiple threads removes the by-value semantics seamlessly. The resulting mutable class isn’t thread-safe.</div><div><br></div><div>2.1) Even when passed around a single thread, the resulting class would be passed by reference, so any mutations would have unintended consequences.</div><div><br></div><div>3) We could probably remove some syntax: `mutating` keyword and variable parameters. Also the `var` keyword before a structure could be used to denote reassignment (not mutability), just as it does with classes.</div><div><br></div><div>Of corse I might not be seeing the whole picture, so please weigh in.</div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=t5fkNsX-2F7-2FAygTFNPNE08PALgkjkO6I8wpsdssDS0uhzD3EyON0qfaM-2BbDYaPGa4azavBvUgXrcfIjbzgpxE8eP9166AITzK3ots1xL7ZbX7ZYqgZjOge2IKsot-2FFjNUORr0LjCExRUPumI8I-2BZoBO7yyqFqYpqCAk5TqOB5aWgB9OMHq0v4txo-2BHeGuoLN9wTozGfCQnGAys309-2B-2Biow4Vc-2FxAZMKOilKYVoGIgGMI-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span> </span>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></blockquote></div></blockquote></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=AxVqvhl7qaAz-2FE20TrrgNT-2F44XdgxmRgRA416dJII-2BS-2BJDOiVIu0C2Vav56WR9LMUCN4ixgGy1FMCLSy4WDlPnLDLlfm4ykymGh7BovnNSIawVpbDYNtfTTx-2FHQ3C0oHzqEN54vbWFeDkkzfRiUsNSozCP26069l-2BKWwkQum0w9hj0eCrRdMn9s19weZHzHDmwi2UC2-2Fcu-2B45iQFLAzGXht9DnjiNHMjDuNyOTw6Xw4-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k7-2FKh2S4pmdp7AzGaXUkMPDqhNCTAweR-2BLq-2BNCoLPKbqWD5FHvUy97cq2SDOJuxSLAGed94S6GjK1wYUcThvEFFHlYUkHNamDoSAUjpZsuD-2BqiMiIOuWMEW912r9IH1h9yvwgiM87o9CScRGufZliATdBznnsZUbGvxEj1e0kfXD1SDdU6i1AolFjqKAjaBWdI-3D" alt="" width="1" height="1" border="0" style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=zCg-2FSGF9Wk188a6c55kLyEbrj7YhaXxFEHM-2F-2B0YAlzVYkgBXXk2E0bcHdR9tRK-2Fl58ZfqL2kx-2BRa7HYDpUooci-2BctQTgFmAr5mMq8-2FGls7PFB5AzXlmyrHOAXDbnAsEUepx8R4xR6iQKOd1L1W0yIKfZzxFG68-2Fw6tprr0dySw1aatq8P-2BzjpKvwbDD-2B3wYpyR66ADF-2FGi6-2BN8bgat-2F0l-2Bz6jVm1gNyqNXHRJbGiKI0-3D" alt="" width="1" height="1" border="0" style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:HelveticaNeue;font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div></blockquote></div>