[swift-evolution] [Discussion] Here we go again: Extension Functions
Brent Royal-Gordon
brent at architechies.com
Mon Feb 29 17:38:15 CST 2016
> - I fear that this can be awfully confusing because there’s no indication on call site that the closure has a different `self`.
> - what if you do want to use your “outer self” inside the self-binding closure? Sure, in some cases, you could differentiate by `foo` and `self.foo`, but I suspect most self-binding closures would also be @noescape. And so, back to the JavaScript-like convention of `let this = self`? Ugh :(
Personally, I wouldn't mind having the feature structured in the following fashion:
* You can use `self` as the internal name of any parameter to any function. (Though perhaps not in a method, which already has an implicit parameter with the internal name `self`.)
* If you do, that parameter is the receiver of all receiverless method calls.
* A closure with `self: T` in its parameter list is simply a hint to SourceKit that its code completion should name the parameter `self`.
That way, any closure which rebound self would be explicitly marked at the top with `self in`, and if you wanted to access the outer `self`, you could always simply give the parameter a different name.
This would add a small syntactic burden to uses of `with` and other DSLs, but it might be worth it to make the behavior explicit.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list