<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 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 class=""><br class=""></div><div class="">Leaving aside those technicalities, it's pretty clear that `foo.bar` should access a method, not an instance variable, 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><br class=""></div><div>Exactly. My example was a bit contrived but that’s what I wanted to say.</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="">Bottom line: Ruby cannot be bridged naturally with just an undifferentiated "access member" hook. It needs separate "access property" and "access method" hooks.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></div></div></blockquote></div><br class=""></body></html>