[swift-evolution] thoughts on 'inout'

Alexey Demedetskiy dalog at me.com
Fri Feb 12 01:54:34 CST 2016


I would like to read it exactly opposite :)

func addInt(inout a: Int, inout b: Int) 
addInt(inout a, inout b)

But +1 for unified semantic anyway.

> func addInt(a:&Int, b:&Int)
> addInt(&a,&b)

> Cc:"swift-evolution at swift.org"<swift-evolution at swift.org>
> Subject:[swift-evolution] thoughts on 'inout'
> Date:12 февраля 2016 г., 01:51:10 GMT+2
> 
> 
> If we were to change stuff for greater conciseness, don’t you think
> 
> func addInt(a:&Int, b:&Int)
> addInt(&a,&b)
> 
> would be a less confusing solution than messing with : and = ?
> — Radek
> > On 12 Feb 2016, at 00:17, Oliver M via swift-evolution<swift-evolution at swift.org(mailto:swift-evolution at swift.org)>wrote:
> > Regarding In-Out Parameters:
> > 
> > My gut reaction to typing 'inout' in front of every parameter I want to call by reference is that it makes code look rather waffly.
> > 
> > So I'm reflecting an idea on this:
> > 
> > 
> > Use = to assign values.
> > 
> > Use : to associate variables.
> > 
> > 
> > 
> > A function declaration would look like this:
> > 
> > func addInt(add intToAdd = Int, to counterInt : Int ) {
> > counterInt += intToAdd
> > }
> > 
> > 
> > 
> > Here is example code for a game of 'think of a number' where you pick a random number and do some basic maths on it.
> > 
> > //declare the function
> > 
> > func multiplyAdd(multiplyBy intToMultiply = Int, add intToAdd = Int, toNumber pickedInt : Int) {
> > pickedInt*= intToMultiply
> > pickedInt+= intToAdd
> > }
> > 
> > 
> > //declare some variables
> > 
> > var multiplier = 2
> > var adder = 3
> > var pickNumber = 4
> > 
> > 
> > //call the function
> > 
> > multiplyAdd(multiplyBy = multiplier, add = adder, toNumber : pickNumber)
> > 
> > 
> > It takes a little getting used to, but it does look quite clean.
> > 
> > 
> > 
> > 
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org(mailto:swift-evolution at swift.org)
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 


More information about the swift-evolution mailing list