Beginner here, so this may be obvious to some people, but I can't figure out why the first argument in a function call isn't referenced by name, but all subsequent ones are. I think I have the syntax down, but I just don't get why it is that way.
For example:
func add(notRequired: Int, required: Int) -> Int {
return notRequired + required
}
let result = add(2, required: 5)
// Not allowed:
// let result = add(notRequired: 2, required: 5)
The given rationale is that the first argument is often the "direct object" to a subject-verb phrase formed by a method call, and hence deserves privileged treatment. There's actually a thread going on in the swift-evolution mailing list about whether this should be changed.
Best,
Austin
···
On Jan 23, 2016, at 12:02 PM, David Keck via swift-users <swift-users@swift.org> wrote:
Beginner here, so this may be obvious to some people, but I can't figure out why the first argument in a function call isn't referenced by name, but all subsequent ones are. I think I have the syntax down, but I just don't get why it is that way.
For example:
func add(notRequired: Int, required: Int) -> Int {
return notRequired + required
}
let result = add(2, required: 5)
// Not allowed:
// let result = add(notRequired: 2, required: 5)
Dne 23.1.2016 v 21:02 David Keck via swift-users napsal(a):
···
Beginner here, so this may be obvious to some people, but I can't figure out why the first argument in a function call isn't referenced by name, but all subsequent ones are. I think I have the syntax down, but I just don't get why it is that way.
For example:
func add(notRequired: Int, required: Int) -> Int {
return notRequired + required
}
let result = add(2, required: 5)
// Not allowed:
// let result = add(notRequired: 2, required: 5)