[swift-evolution] Reconsidering SE-0003 Removing var from Function Parameters and Pattern Matching

Charles Srstka cocoadev at charlessoft.com
Mon Jan 25 06:12:41 CST 2016


> On Jan 25, 2016, at 3:54 AM, Quinn The Eskimo! via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> On 25 Jan 2016, at 03:25, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On 25 Jan 2016, at 01:44, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>> But that’s not what assigning something to a var means in any other context. Why should it be any different here?
>> 
> 
>> I made the same argument myself, but you can't argue with empirical
>> evidence: some people have been tripped up by this anyway.
> 
> One explanation might be that these folks have a Pascal heritage, where "var" is (roughly) equivalent to Swift's "inout”.

Perhaps then we should add an “if inout” construct, then, so that the distinction between “inout” and “var” here are clear for people to see, and explained in the documentation?

As a bonus, I can think of a few situations where “if inout” would be useful—particularly so we wouldn’t need the postfix ! to do things like this:

if someStruct.someOptionalArray != nil {
	someStruct.someOptionalArray!.append(foo)
}

With “if inout”, you could do this instead:

if inout array = someStruct.someOptionalArray {
	array.append(foo)
}

which seems quite a bit cleaner.

Charles



More information about the swift-evolution mailing list