<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 doesn't make sense to me. If it's sometimes necessary to reassign a struct containing a single reference, then surely it may be necessary to reassign a single reference not contained in a struct.</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 26, 2016, at 20:37 , Nate Birkholz via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">Seems in line with other compiler warnings.<br class=""><br class="">Sent from my iPhone, please excuse brevity and errors</div><div class=""><br class="">On Jan 26, 2016, at 8:30 PM, J. Cheyo Jimenez via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">Would it be confusing if `guard var ` or `if var ` <span class=""></span>was only allowed for value types? </div><br class=""><div class=""><br class="">On Tuesday, January 26, 2016, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
on Tue Jan 26 2016, Tian Zhang <<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')" class="">swift-evolution@swift.org</a>> wrote:<br class="">
<br class="">
> I’m also curious how most people fix “guard var” or “if var”?<br class="">
> Especially for checking a class object for protocol conformation and<br class="">
> set variable on the object?<br class="">
><br class="">
> like in this case,<br class="">
><br class="">
>> if var vc = vc as? ControlPanelConfigurationProtocol {<br class="">
>> vc.servicePresentationObject = service<br class="">
>> vc.presentAsPanel = true<br class="">
>> }<br class="">
><br class="">
> become<br class="">
><br class="">
>> if let vc = vc as? ControlPanelConfigurationProtocol {<br class="">
>> var vc = vc<br class="">
>><br class="">
>> vc.servicePresentationObject = service<br class="">
>> vc.presentAsPanel = true<br class="">
>> }<br class="">
<br class="">
<br class="">
If vc has class type, you don't need the var at all.<br class="">
<br class="">
> I saw a few people suggest to create a method on the protocol like<br class="">
> “configureObject(...)” with all potential args and have the object to<br class="">
> figure it out but doing so I feel we’re losing the benefits offered by<br class="">
> property observation for the underlying object. Using pattern “if let”<br class="">
> with a “var” in the block just to make the property mutable again<br class="">
> feels really strange.<br class="">
><br class="">
> Best Wishes,<br class="">
> Tian<br class="">
>> An alternative would certainly be interesting but I would prefer to<br class="">
>> take it one step at a time and avoid being hasty so we can come up<br class="">
>> with something really great. What did most of your var fixes look<br class="">
>> like, by the way? Did you end up changing the layout of your value<br class="">
>> types or did you decide to add more vars?<br class="">
>><br class="">
>> David<br class="">
>><br class="">
>> > On Jan 24, 2016, at 7:19 PM, Zach Waldowski via swift-evolution<br class="">
>> > <swift-evolution at <a href="http://swift.org/" target="_blank" class="">swift.org</a><br class="">
>> > <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>>> wrote:<br class="">
>> ><br class="">
>> > -1<br class="">
>> ><br class="">
>> > Having already adopted the syntax in my projects in anticipation of 2.2,<br class="">
>> > the increase in clarity at the expense of terseness is appreciated. A<br class="">
>> > proposal should not be discussing an alternative, not a rollback.<br class="">
>> ><br class="">
>> > Cheers!<br class="">
>> > Zachary Waldowski<br class="">
>> > zach at <a href="http://waldowski.me/" target="_blank" class="">waldowski.me</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="">
>> ><br class="">
>> > On Fri, Jan 22, 2016, at 12:26 PM, David Farler via swift-evolution<br class="">
>> > wrote:<br class="">
>> >> Hello everyone,<br class="">
>> >><br class="">
>> >> I'd like to reconsider SE-0003 for Swift 3 and propose cancelling the<br class="">
>> >> change in its entirety. After collecting feedback since Swift's open<br class="">
>> >> source launch, I no longer feel this is a good move and there are a few<br class="">
>> >> reasons why.<br class="">
>> >><br class="">
>> >> There are two main patterns that the removal penalizes:<br class="">
>> >><br class="">
>> >> - Get-Modify-Reassign<br class="">
>> >> - Get-Modify-Return<br class="">
>> >><br class="">
>> >> I've found that many of the problems with this proposal stem from the<br class="">
>> >> uses before and after the "Modify" part, before returning or reassigning<br class="">
>> >> with the new value.<br class="">
>> >><br class="">
>> >> I've seen a few common responses to the var removal. Consider a<br class="">
>> >> `Rectangle` struct:<br class="">
>> >><br class="">
>> >><br class="">
>> >> struct Rectangle {<br class="">
>> >> var origin: (x: Double, y: Double)<br class="">
>> >> var size: (width: Double, height: Double)<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> Even with mutable variables `origin` and `size`, this pattern would be<br class="">
>> >> impossible:<br class="">
>> >><br class="">
>> >><br class="">
>> >> var selection = getRectangularSelection()<br class="">
>> >> if var rect = selection?.rect {<br class="">
>> >> // Mutate `rect` ...<br class="">
>> >> selection.rect = rect<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> So, one might shadow the variable, which is not ideal:<br class="">
>> >><br class="">
>> >><br class="">
>> >> var selection = getRectangularSelection()<br class="">
>> >> if let rect = selection?.rect {<br class="">
>> >> var rect = rect // Not so great<br class="">
>> >> // Mutate `rect` ...<br class="">
>> >> selection.rect = rect<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> Or, you might make a transformation function on `Rect`:<br class="">
>> >><br class="">
>> >><br class="">
>> >> struct Rectangle {<br class="">
>> >> var origin: (x: Double, y: Double)<br class="">
>> >> var size: (width: Double, height: Double)<br class="">
>> >> func withOrigin(x: Double, y: Double) -> Rect {<br class="">
>> >> var r = self<br class="">
>> >> r.origin = (x, y)<br class="">
>> >> return r<br class="">
>> >> }<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> This is a much better solution than shadowing but you would need one of<br class="">
>> >> these for any property that you want to mutate and I think you'll agree<br class="">
>> >> that it doesn't scale with the language we have today. This response begs<br class="">
>> >> for a kind of initializer that takes all of the fields of the original<br class="">
>> >> struct except any that you want to override:<br class="">
>> >><br class="">
>> >><br class="">
>> >> if let rect = selection?.rect.with(origin: newOrigin) {<br class="">
>> >> // ...<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> Straw syntax, but maybe you'll see something along these lines on<br class="">
>> >> swift-evolution in the future, which would provide a clear alternative to<br class="">
>> >> direct mutation patterns. Even then, I think having complementary<br class="">
>> >> patterns in the language isn't a bad thing.<br class="">
>> >><br class="">
>> >> These problems come up with the other variable bindings but the one that<br class="">
>> >> ended up bothering me the most was `guard var`:<br class="">
>> >><br class="">
>> >><br class="">
>> >> func transform(selection: Rect?) {<br class="">
>> >> guard let rect = selection else { return }<br class="">
>> >> var _rect = rect<br class="">
>> >> // Mutate `_rect` ...<br class="">
>> >> }<br class="">
>> >><br class="">
>> >><br class="">
>> >> One of the guard statement's main purposes is to conditionally bind a<br class="">
>> >> value as a peer in its own scope, not an inner scope like if statements.<br class="">
>> >> Not having var makes the guard statement much weaker.<br class="">
>> >><br class="">
>> >> There is certainly a bit of confusion about the nuances between value and<br class="">
>> >> reference semantics, who owns a value and when, how effects are<br class="">
>> >> propagated back to values, but I think we can attack the problem with<br class="">
>> >> more finesse.<br class="">
>> >><br class="">
>> >> Value types are one of the attractive features of Swift – because of<br class="">
>> >> their semantics, mutating algorithms are written in a familiar style but<br class="">
>> >> keeping effects limited to your unique reference. I don't think we should<br class="">
>> >> give that up now to address confusion about semantics, out of principle,<br class="">
>> >> or in anticipation of new language features. I propose cancelling this<br class="">
>> >> change for Swift 3 and continue to allow `var` in the grammar everywhere<br class="">
>> >> it occurs in Swift 2.2.<br class="">
>> >><br class="">
>> >> Regards,<br class="">
>> >> David<br class="">
>> >> _______________________________________________<br class="">
>> >> swift-evolution mailing list<br class="">
>> >> swift-evolution at <a href="http://swift.org/" target="_blank" class="">swift.org</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="">
>> >> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
>> >> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="">
>> > _______________________________________________<br class="">
>> > swift-evolution mailing list<br class="">
>> > swift-evolution at <a href="http://swift.org/" target="_blank" class="">swift.org</a> <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="">
>> > <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
>> > <<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="">
> _______________________________________________<br class="">
> swift-evolution mailing list<br class="">
> <a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')" class="">swift-evolution@swift.org</a><br class="">
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
--<br class="">
-Dave<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>