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

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


On Nov 11, 2017, at 2:04 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> I generally dislike „protocol magic“, but I think in this case, there is also a precedence for an (imho) better way:
> There’s no „Subscriptable“ protocol, and I would prefer callable types to be handled in the same way (afaics, subscripts are already used as „callable with different braces“ today in some cases).
> 
> You mention subscripts in „Alternatives considered“, but without an explanation why you don’t want a new declaration kind for dynamicCall — and I think it could co-exist with the orthogonal use case that you mention.

Sure, this is a great question.  We could definitely introduce a new declaration kind.  The tradeoff I see is that that is far more language invasive, and that none of our existing decls work this way: packaging up syntax (keyword labels) and handing it off.

One theoretical way to address this is to introduce a macro system, but that would be far more invasive and isn’t going to happen now (and perhaps never?).

Despite the claims, the impact of this proposal on the compiler is extremely narrow.

-Chris



More information about the swift-evolution mailing list