[swift-evolution] Python Interop with Swift 4+

David Waite david at alkaline-solutions.com
Mon Nov 20 15:41:10 CST 2017

In ruby, parens are optional. So,

v = foo.value


v = foo.value()

are identical. There dot syntax is only used for method invocation, so there is no external access to instance variables without some twiddling; similarly getting access to a Proc/lambda/Method requires twiddling in Ruby (although there are shortcuts in normal use, like Symbol#to_proc)

Ruby class implementations often expose a getter and/or setter for instance variables - under the function names example_value() and example_value=(). If instance variables/class variables are not exposed in this manner, then the expectation is that you weren’t meant to see/manipulate them, and do so at your own peril.

For mapping to Swift, I would say that parens are needed; we can’t guess whether a `foo.bar` is meant to be asking for the value of attribute bar or a reference to method bar.

More difficult would be the use of ‘=‘, ‘!’, and ‘?’ - all legal in Ruby method names as suffixes. ‘=‘ as already stated is used for setters, ‘!’ for differentiating mutating operations, and ‘?’ to indicate the result is boolean (or sometimes just ‘truthy’ , as every object other than false and nil evaluate to true)

I could imagine tricks to make `foo.bar = 1` work, but I’m not sure what would be an appropriate way to represent ! and ? methods.


> On Nov 20, 2017, at 1:10 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>> On Nov 20, 2017, at 10:50 AM, Slava Pestov via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Nov 20, 2017, at 1:39 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> It is straight-forward (and fits very very naturally into the Swift call model) to support the second one as an atomic thing, which is I think what you’re getting at. 
>> What if you write ‘let fn = obj.method’?
> That’s related to the DynamicMemberLookup proposal.  I’m not familiar with Ruby, but it sounds like the implementation would end up calling rb_iv_get/set to manipulate instance variables.  Is that your question or are you asking something else?
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171120/d2d469cb/attachment.html>

More information about the swift-evolution mailing list