<div dir="ltr">Is the choice of backslash up for review? I think another operator, perhaps backtick (`), would work better. My concern is with the \() escaping syntax within strings, which has the opposite behavior wrt. execution time:<div><br></div><div><div>let untrue = "2 + 2 = \((5, print("inside")).0)"</div><div>print("outside")</div><div>print(untrue)</div><div>// output:</div><div>// "inside"</div><div>// "outside"</div><div>// "2 + 2 = 5"</div><div><div><br></div><div>If the purpose of the backslash syntax is to make the delayed execution time clear, I don't believe it achieves that goal.</div><div><br></div><div>Love the proposal otherwise, and I for sure see the logic in making Person.instanceMethod "look different" from Person.classOrStaticProperty.</div><div><br></div><div>-Colin</div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 5, 2017 at 7:01 PM Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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" class="gmail_msg">Proposal Link: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md" class="gmail_msg" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md</a><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">Hello Swift community,<br class="gmail_msg"><br class="gmail_msg">The review of SE-0161 “Smart KeyPaths: Better Key-Value Coding for Swift” ran from March 30...April 5, 2017. The proposal was very well-received *except* that reviewers felt that the <font face="Menlo" class="gmail_msg">#keyPath</font> syntax was far too heavy for this new language construct, and preferred the lighter-weight syntax of the pre-review drafts. This proposal is <b class="gmail_msg">returned for revision</b> to address the syntax.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The heavyweight <font face="Menlo" class="gmail_msg">#keyPath</font> syntax was requested by the core team after reviewing earlier drafts, which used a far lighter syntax:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>// (Rejected) syntax from pre-review drafts</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>let firstFriendsNameKeyPath = Person.friends[0].name</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>print(luke[keyPath: .friends[0].name])</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The core team’s specific concern was that these key path expressions (e.g., <font face="Menlo" class="gmail_msg">Person.friends[0].name</font>) don’t make it sufficiently clear that the actual property accesses are being delayed, and that the contextual cues (“<font face="Menlo" class="gmail_msg">Person.</font>" vs. “<font face="Menlo" class="gmail_msg">luke.</font>”) are insufficient to disambiguate for the human reader. Hence, the request for a different (more explicit) syntax.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Reviewers rightly point out that it is natural for key-paths to use the same syntax as unapplied instance method references, e.g., <font face="Menlo" class="gmail_msg">Person.someInstanceMethod</font> produces a value of some function type with the “Self” type curried, e.g.,<font face="Menlo" class="gmail_msg"> (Person) -> (param-types) -> result-type</font>. The core team agrees with this sentiment. The core team also felt that Swift’s existing unapplied method references suffer from the same clarity problems as the initial key-path syntax, i.e., that it isn’t sufficiently clear that the actual application of “self” is being delayed.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The core team has a specific proposal: use the backslash (‘<font face="Menlo" class="gmail_msg">\</font>’) to as a leading indicator for key paths. Specifically,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>// Proposed syntax for second revision</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>let firstFriendsNameKeyPath = \Person.friends[0].name</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>print(luke[keyPath: \.friends[0].name])</font></div></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg">The backslash is a visual cue that the actual application of this chain of property references is delayed, eliminating ambiguities, yet is still quite lightweight and feels “first-class” in the language.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The core team felt that, in the future, the backslash should also be used for unapplied instance method references, to match the proposed syntax for key paths and improve clarity for this non obvious feature. This change could be staged in as a revision to the accepted-but-never-implemented <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0042-flatten-method-types.md" class="gmail_msg" target="_blank">SE-0042: Flattening the function type of unapplied method references</a>, e.g.,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>// Proposed future syntax for unapplied instance method references</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> class Person {</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span> func instanceMethod(_: String) -> Int { … }</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>}</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>let f1 = Person.instanceMethod // to-be-deprecated; produces a value of type (Person) -> (String) -> Int</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>let f2 = \Person.instanceMethod // to-be-introduced via a revised SE-0042: produces a value of type (Person, String) -> Int</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Such an approach gives us a way to stage in SE-0042 and get to eventual consistency between key paths and unapplied instance method references.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>- Doug</div><div class="gmail_msg"><span class="m_-5170646606332262420Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>Review Manager</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"></div></div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div></div></div></div></div>