<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">No, I meant the code I showed <i class="">already</i> works by the principle I stated. Dot-prefixed member access always looks up in a contextual type for a member returning the same type. Your example here has nothing to do about lexical scoping; it just means we don't take subtypes into account when we could.</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 16, 2016, at 16:59, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Jordan,<div class=""><br class=""></div><div class="">Yes implementing `==` will patch the example I gave, but it isn't a general solution. Consider this variation:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="">class Static: Equatable {<br class=""> class One: Static {}<br class=""> static let one = One()<br class=""> class Two: Static {}<br class=""> static let two = Two()<br class=""> func e() -> String {<br class=""> switch self {<br class=""> case Static.one:<br class=""> return "one"<br class=""> case Static.two :<br class=""> return "two"<br class=""> default:<br class=""> return "unknown"<br class=""> }<br class=""> }<br class="">}<br class="">func ==(lhs: Static, rhs: Static) -> Bool {<br class=""> return lhs === rhs<br class="">}<br class=""><br class=""></blockquote>Still needs the type qualifiers :(.</div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"> -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 17 February 2016 at 11:31, Jordan Rose <span dir="ltr" class=""><<a href="mailto:jordan_rose@apple.com" target="_blank" class="">jordan_rose@apple.com</a>></span> wrote:<br class=""><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=""><div class="">That works just as well outside the enum:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">enum Enum {</div><div class=""> case one</div><div class=""> case two</div><div class="">}</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class=""><div class="">func e(value: Enum) -> String {</div></div><div class=""><div class=""> if value == .one {</div></div><div class=""><div class=""> return "one"</div></div><div class=""><div class=""> } else if value == .two {</div></div><div class=""><div class=""> return "two"</div></div><div class=""><div class=""> }</div></div><div class=""><div class=""> return "unkown"</div></div><div class=""><div class="">}</div></div></blockquote><div class=""><br class=""></div><div class="">Here it's looking in the contextual type provided by ==. The enum synthesizes a function along the lines of</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">func ==(a: Enum, b: Enum)</div></blockquote><div class=""><br class=""></div>This doesn't work for === because you can compare identity across class types.<div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">func ===(a: AnyObject, b: AnyObject)</div></blockquote><div class=""><div class=""><div class=""><br class=""></div><div class="">Jordan<br class=""><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 16, 2016, at 16:20, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" target="_blank" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">@Jordan,<div class=""><br class=""></div><div class="">You said "<span style="font-size:12.8px" class="">I don't think we want to change or overload that rule to also look up static members of the </span><i style="font-size:12.8px" class="">enclosing lexical context type</i><span style="font-size:12.8px" class=""> (i.e. the type of 'self')." </span>But you do already; inside an enum, e.g.:</div><div class=""><br class=""></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class="">enum Enum {<br class=""> case one<br class=""> case two<br class=""> func e() -> String {<br class=""> if self == .one {<br class=""> return "one"<br class=""> } else if self == .two {<br class=""> return "two"<br class=""> }<br class=""> return "unkown"<br class=""> }<br class="">}</blockquote><div class=""><p class="">Compared to inside a static:<br class=""></p>
</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="">class Static {<br class=""> class One: Static {}<br class=""> static let one = One()<br class=""> class Two: Static {}<br class=""> static let two = Two()<br class=""> func e() -> String {<br class=""> if self === Static.one {<br class=""> return "one"<br class=""> } else if self === Static.two {<br class=""> return "two"<br class=""> }<br class=""> return "unknown"<br class=""> }<br class="">}</blockquote><div class=""><p class=""><span class="">Why so different? The enum version looks inside the type `Enum` to find `.one` and `.two`, but the static version doesn't look inside the type `Static` and hence you have to say `Static.one` and `Static.two` :(</span></p></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class=""> -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 16 February 2016 at 05:40, Jordan Rose via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><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=""><div class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 8:58, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">While discussing leading enumeration dot prefixes, Howard Lovatt asked why static properties and methods could not be inferred via a dot prefix as well. Based on Swift-Evolution conventions, here's a new thread to discuss this idea: specifically, would it be beneficial (and/or possible) to use dot prefixes to denote static member references in instance member code.</div><div class=""><br class=""></div><div class="">Howard wrote:</div><div class=""><br class=""></div><div class=""></div><blockquote type="cite" class=""><div class=""><span style="font-family:Palatino-Roman" class="">+1 for the proposal, it is wierd to use `.` in some places and not others. </span><div style="font-family:Palatino-Roman" class=""><br class=""></div><div style="font-family:Palatino-Roman" class="">On the subject of static methods and properties in general, would it be possible for `.name` to be a reference to a static and `name` a reference to an instance? EG:</div><div style="font-family:Palatino-Roman" class=""><br class=""></div><div class=""><font face="Menlo" class=""> .name = x // static</font></div><div class=""><font face="Menlo" class=""> name = x // instance</font></div><div class=""><font face="Menlo" class=""> x = name + .name // instance + static</font></div><div class=""><font face="Menlo" class=""> r = name ... .name // instance ... static, needs space</font></div><div class=""><font face="Menlo" class=""> r = name...Type.name // Can still qualify with type name</font></div></div><div style="font-family:Palatino-Roman" class=""><br class=""></div></blockquote><div class=""><br class=""></div><span class="">Under the current system, you must explicitly name or derive a type to access static members from instance member implementations.</span><div style="font-size:8px" class=""><br style="font-size:8px" class=""></div><div style="font-size:8px" class=""><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">struct</span> MyStruct {</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""> <span style="color:#bb2ca2" class="">static</span> <span style="color:#bb2ca2" class="">func</span> staticMember() {}</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;min-height:21px" class=""> <br class=""></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""> <span style="color:#bb2ca2" class="">func</span> instanceMember() {</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="color:rgb(0,132,0)" class=""> // name a type</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""> <span style="color:rgb(79,129,135)" class="">MyStruct</span>.<span style="color:rgb(49,89,93)" class="">staticMember</span>() <span style="color:rgb(0,132,0)" class="">// works</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="color:rgb(0,132,0)" class=""><br class=""></span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="color:rgb(0,132,0)" class=""> // derive a type</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)" class=""><span class=""> </span>self<span class="">.</span>dynamicType<span class="">.</span><span style="color:#31595d" class="">staticMember</span><span class="">() </span><span style="color:#008400" class="">// works</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""> </div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span class=""> </span>// error: value of tuple type '()' has no member 'staticMember'</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span class=""> </span>// does not work</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""> .staticMember()</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class=""> }</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class="">}</div><div style="font-size:8px" class=""><br style="font-size:8px" class=""></div><div style="font-size:12px" class="">Using dot prefixes for static member access:</div></div><div class=""><br class=""></div><div class="">* Has precedent in enumeration members</div><div class="">* Would streamline Swift code</div><div class="">* Is visually differentiated from `self`-prefixed instance member references</div><div class=""><br class=""></div><div class="">What are your thoughts, both technical and philosophical, on a change like this? Thanks in advance for your feedback.</div></div></div></blockquote><br class=""></div></div></div><div class="">Dot-prefixed member expressions are currently looked up as static members of the<i class=""> contextual type,</i> which lets you do things like this:</div><div class=""><br class=""></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">import AppKit</div><div class="">let colors: [NSColor] = [.redColor(), .blueColor()]</div></blockquote><br class=""><div class="">I don't think we want to change or overload that rule to also look up static members of the <i class="">enclosing lexical context type</i> (i.e. the type of 'self').</div><div class=""><br class=""></div><div class="">Jordan</div></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>