<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 Nov 20, 2017, at 7:08 AM, David Hart 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 20 Nov 2017, at 12:34, Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 20, 2017, at 12:32 AM, David Waite 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 20, 2017, at 1:16 AM, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div></div></div></blockquote><snip></div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Moreover, Ruby allows classes to have instance variables with the same name as methods:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">class Foo</font><div class=""><font face="Menlo" class=""> def initialize()<br class=""> @bar = 5<br class=""> end</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><font face="Menlo" class=""> def bar()</font><div class=""><font face="Menlo" class=""> puts “Hello"</font></div><div class=""><font face="Menlo" class=""> end</font></div><font face="Menlo" class="">end</font></div><div class=""><br class=""></div><div class="">In that case, how would one implement <font face="Menlo" class="">DynamicMemberLookupProtocol</font> for the lookup of <font face="Menlo" class="">bar</font>, and what would the return value be? Its entirely context sensitive.</div></div></div></blockquote><div class=""><br class=""></div>I do not believe Ruby does not give you direct external access to variables. Everything with a ‘.’ is a function call.</div><div class=""><br class=""></div><div class="">You would use e.g.</div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Foo.new.instance_variable_get("@bar”) // => 5</span></div></div><div class=""><br class=""></div><div class="">attr :bar exposes a variable @bar through functions bar() and bar=() (and also optimizes storage in some implementations)</div></div></div></blockquote><br class=""></div><div class="">This is correct…sort of. Ruby uses symbols to refer to both methods and instance variables, but instance variable symbols always start with @, so they effectively belong to a different namespace. (Similarly, symbols starting with a capital letter are for constants; symbols starting with @@ are for class variables; I believe symbols starting with $ are for global variables.) Ruby only provides syntax to access another object's methods and (for a class) constants, so in practice there's no way to access another object's instance variables except by calling a method on it, but there's no particular reason our bridge would need to follow that rule.</div></div></div></blockquote></div></div></div></blockquote><div><br class=""></div><div><div>Just to add a little weight to what Brent wrote here: in Ruby, one can •only• access instance variables of self using the @bar syntax. There is no such thing as “foo.@bar”; as Brent wrote, one can only access another object — not even another class, but another object! — via its methods.</div><div><br class=""></div><div>Class authors thus expect @bar to be private (well, same-instance protected), and instance_variable_get/set is the accepted in-Ruby hack to fiddle with another object’s internal state. I see no reason a bridge would need to deviate from that understanding.</div></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Leaving aside those technicalities, it's pretty clear that `foo.bar` should access a method, not an instance variabl, when `foo` is a Ruby object. That doesn't mean it's the same as Python, though, because in Ruby it will need to *call* the method immediately if we're to provide natural syntax for Ruby objects bridged to Swift.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Exactly. My example was a bit contrived but that’s what I wanted to say.</div></div></div></div></blockquote><div><br class=""></div><div>X-ref to a thread where we discussed this at greater length:</div><div><br class=""></div><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20171113/041447.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20171113/041447.html</a></div><div><br class=""></div><div>Cheers,</div><div><br class=""></div><div>Paul</div></div></body></html>