[swift-evolution] Request for Discussion: Setup closures

Erica Sadun erica at ericasadun.com
Fri Dec 4 15:58:24 CST 2015


I suspect this is an easy compiler catch requiring a forced self for disambiguation the same way as in init

-- E

> On Dec 4, 2015, at 2:51 PM, Michel Fortin <michel.fortin at michelf.ca> wrote:
> 
> Le 4 déc. 2015 à 16:35, Sean Heber <sean at fifthace.com> a écrit :
> 
>> I would also be in favor of something more generally applicable rather than making initialization more special. I think I prefer the block-style over Dart’s approach. Smalltalk uses semicolons for this, if I recall. I’m not sure I like using a special operator. I’m obviously a keyword guy.. :P
>> 
>> with let task = NSTask() {
>>  launchPath = "/usr/bin/mdfind"
>>  arguments = ["kMDItemDisplayName == *.playground"]
>>  standardOutput = pipe
>> }
>> 
>> Also valid:
>> 
>> with someVariable {
>>  func1()
>>  func2(“etc")
>> }
>> 
>> Which would call func1() and func2() on the someVariable instance (which I think would be quite expected).
> 
> The problem with this approach is that it can become ambiguous with the outer scope pretty easily, if not to the compiler at least for the reader:
> 
> 	let launchPath = "a.out"
> 	let description = "blah blah"
> 	with let task = NSTask() {
> 		launchPath = launchPath // eh, what?
> 		arguments = [launchPath, description] // is that task.description?
> 	}
> 
> I think it's important that things referring to the "task" in the above example be syntactically distinguishable.
> 
> It can also lead to code breakage:
> 
> 	let path = "a.out"
> 	with let task = NSTask() {
> 		launchPath = path
> 	}
> 
> That would work fine one day, but what if in the next OS release NSTask gets a new "path" property? That code breaks silently once you recompile with the newer SDK.
> 	
> 
> -- 
> Michel Fortin
> michel.fortin at michelf.ca
> https://michelf.ca
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list