<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2017, at 12:13 PM, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><div class=""><div class=""><font face="Menlo" class="">let result = <b class="">dynamic</b> x.foo.bar // will crash if foo or bar are not present</font></div><div class=""><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let result = <b class="">dynamic?</b> x.foo.bar // will return nil if foo or bar are not present</font></div></div></div></div></div></blockquote><br class=""></div><div>Under the proposal given here, the compiler doesn’t know what will happen when “foo” or “bar” are not present. This proposal does not even require the implementation to <i class="">report</i> if a member is present or not, and there is certainly no guarantee of a crash in such a case. The only thing the compiler knows is that <font face="Menlo" class="">subscript(dynamicMember:)</font> will be called.</div><div><br class=""></div><div>Consider the following implementation:</div><div> </div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(186, 45, 162);" class="">struct</span><span style="color: rgb(0, 0, 0);" class=""> PyVal: </span>DynamicMemberLookupProtocol<span style="color: rgb(0, 0, 0);" class=""> {</span></div></div><div><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> </p></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">subscript</span>(dynamicMember: <span style="color: #703daa" class="">String</span>) -> <span style="color: #4f8187" class="">PyVal</span>? {</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">if</span> <span style="color: #ba2da2" class="">let</span> pythonMember = <span class="">p</span><span class="">ython_c_api.get(dynamicMember) {</span></div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">return</span> <span style="color: #4f8187" class="">PyVal</span>(pythonMember)</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">else</span> {</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">nil</span></div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</div></div><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">let result = x.foo?.bar</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div></div></blockquote><div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">There is no crashing here; result will be an optional type, and will be nil if the requested property does not exist. Some other use of DynamicMemberLookupProtocol might accept any value, and just log it to a file! In that case, neither crashing nor returning an optional is required.</div></div><div><br class=""></div><div>-BJ</div></body></html>