[swift-evolution] [Idea] Custom default names for arguments of closures

Myles Schultz myleslschultz at icloud.com
Sun Feb 14 18:14:08 CST 2016


Agreed, -1, I actually prefer using $0, $1, etc. 

Myles

Sent from my iPhone

> On Feb 14, 2016, at 6:04 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Sorry, not keen. Too much overlap with labels, therefore not worth the addition.
> 
>   -- Howard.
> 
>> On 14 February 2016 at 07:38, Eugene Gubin via swift-evolution <swift-evolution at swift.org> wrote:
>> Right now Swift provides shorthand argument names ($0, $1 etc) by default which could be overriden with more specific names. I think it would be nice to define our own default names as part of type definition:
>> 
>> typealias Closure = (first one: String, second two: String) -> Void
>> 
>> func executeClosure(closure: Closure) {
>> 	// the caller uses external parameter names, nothing changed here 
>> 	closure(first: "first", second: 2)
>> }
>> 
>> executeClosure {
>> 	// the callee uses custom arguments instead of $0, $1
>> 	// also it is possible to override these names here as usual 
>> 	print("one \(one) two \(two)")
>> }
>> 
>> This feature is backward compatible in that way what both
>> 
>> typealias Closure = (first: String, second: String) -> Void 
>> 
>> and
>> 
>> typealias Closure = (String, String) -> Void
>> 
>> will provide the same behavior like now.
>> 
>> Possible applications: providing default argument names more meaningfull than $0, $1, DSL-like constructions.
>> 
>> Possible problem: names could overlap. Nothing new. $0, $1 could overlap too. Override argument names or variable names in a scope.
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> 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/20160214/64d4bcf3/attachment.html>


More information about the swift-evolution mailing list