<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="">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="">&nbsp; &nbsp; case one</div><div class="">&nbsp; &nbsp; 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) -&gt; String {</div></div><div class=""><div class="">&nbsp; &nbsp; if&nbsp;value&nbsp;== .one {</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return "one"</div></div><div class=""><div class="">&nbsp; &nbsp; } else if&nbsp;value&nbsp;== .two {</div></div><div class=""><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return "two"</div></div><div class=""><div class="">&nbsp; &nbsp; }</div></div><div class=""><div class="">&nbsp; &nbsp; 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><blockquote type="cite" class=""><div class="">On Feb 16, 2016, at 16:20, Howard Lovatt &lt;<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><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&nbsp;</span><i style="font-size:12.8px" class="">enclosing lexical context type</i><span style="font-size:12.8px" class="">&nbsp;(i.e. the type of 'self')."&nbsp;</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="">&nbsp; &nbsp; case one<br class="">&nbsp; &nbsp; case two<br class="">&nbsp; &nbsp; func e() -&gt; String {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; if self == .one {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "one"<br class="">&nbsp; &nbsp; &nbsp; &nbsp; } else if self == .two {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "two"<br class="">&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return "unkown"<br class="">&nbsp; &nbsp; }<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="">&nbsp; &nbsp; class One: Static {}<br class="">&nbsp; &nbsp; static let one = One()<br class="">&nbsp; &nbsp; class Two: Static {}<br class="">&nbsp; &nbsp; static let two = Two()<br class="">&nbsp; &nbsp; func e() -&gt; String {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; if self === Static.one {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "one"<br class="">&nbsp; &nbsp; &nbsp; &nbsp; } else if self === Static.two {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "two"<br class="">&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">&nbsp; &nbsp; &nbsp; &nbsp; return "unknown"<br class="">&nbsp; &nbsp; }<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="gmail_signature">&nbsp; -- 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="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</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="h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 15, 2016, at 8:58, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; 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.&nbsp;</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="">&nbsp; &nbsp; .name = x // static</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; name = x // instance</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; x = name + .name // instance + static</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; r = name ... .name // instance ... static, needs space</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; 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="">&nbsp; &nbsp; <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="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; <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="">&nbsp; &nbsp; &nbsp; &nbsp; // name a type</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(79,129,135)" class="">MyStruct</span>.<span style="color:rgb(49,89,93)" class="">staticMember</span>()&nbsp;<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="">&nbsp; &nbsp; &nbsp; &nbsp; // 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="">&nbsp; &nbsp; &nbsp; &nbsp; </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="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </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="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// does not work</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; .staticMember()</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</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="">&nbsp;contextual type,</i>&nbsp;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>&nbsp;(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" 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></body></html>