[swift-evolution] [Pitch] Introduce user-defined dynamically "callable" types

Chris Lattner sabre at nondot.org
Sat Nov 11 12:12:50 CST 2017


On Nov 11, 2017, at 6:52 AM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>> I don't think it's that localized. It's going to make call resolution massively more complicated.  Through great pain and community anguish, we pushed ourselves to a model where argument labels are parts of the declaration name, not part of the call argument, and this would throw us straight back into the kinds of complications of dealing with overloaded name- and type-dependent behavior we're trying to get away from in the language.
>> 
>> I’m pretty sure it doesn’t, but good news: since Swift requires an implementation before the proposal can be officially reviewed, you will be able to look at the actual patch to make this decision.
> 
> And the goal of the pitch phase is to hopefully save you the tears of trying to implement something if it's a bad idea.

Appreciated.  Fortunately I enjoy coding so it’s not that big of a deal for me.

>>> Swift is a dynamic language too, and tuples have enough metadata in them that you could get almost everything you want with an infix operator.
>> 
>> This is really gross.  The goal here is to make Python feel natural.  If you oppose this proposal then we’ll have to find some other way to provide an elegant experience:
>>> x∫(0, "foo", bar: "bas”)
>> 
>> This is not going to be acceptable to users.
> 
> Is it? My choice of operator character is silly, but it's the same amount of syntactic overhead as an optional chain/force call. It's a fair sight better than x.call(args: ..., keywordArgs: ...), I hope you'd agree, and is something that works without any language change.

Yes, I’m happy to explore that, and I agree this approach doesn’t require language changes.  That said, there are three things you should understand:

1) Details matter.  While you claim that there is some other operator character that could be awesome, I’m not seeing it.  Can you try harder to come up with something that you think would be acceptable?

2) The point of the entire proposal is that a certain audience will be using the feature enabled by this (python interop) *a lot*, so ergonomics matter.

3) This feature (python interop) is aimed to get Python programmers to convert to Swift, not simply to ease friction for existing Swift programmers (most of whom are iOS developers, to whom this feature is completely irrelevant).  Getting people to move from Python to Swift is a challenge, and syntax does actually matter. I hope we can agree that expanding the community of Swift developers is a laudable goal.  

> You mentioned variadics as being inadequate for your purposes as a considered alternative, but a variadics model that wasn't based on type erasure to arrays and kept runtime type information about the argument tuple that was passed in, along with better reflection APIs for accessing that type info, might lead to something you can use by incrementally improving the expressivity of existing language features instead of adding new ones.

I’m not sure what you mean by this: variadics are fine. The hard part is getting the keyword arguments for a call dynamically.  Can you point to what you’re referring to in the proposal?

-Chris



More information about the swift-evolution mailing list