[Accepted with Modification] SE-0253 - Callable values of user-defined nominal types

If this is really going to be a function (which I very much disagree should happen, but oh well), then IMO there's really only a single of logical name for what it should be:

func _ (arg1: Type1)

This is not a feature like subscript, because we've decided we're still going to have func as part of the signature, which is not the case when declaring a subscript-able type. Therefore, I don't think we need an additional special keyword-name.

What we're technically describing here is the ability to call a function on a type, but where that function does not have a name. In Swift, the syntax for "this is unnamed" is to use _. So having the callable function be func _ (...) is consistent with existing syntax, because it means "This is a function, but it has no name", which implies you'd call it by omitting the name, which means it is the "callable" function:

struct Adder {
    let base: Int
    func _ (adding value: Int) -> Int { return base + value }
}

let a = Adder(base: 40)
let answer = a(adding: 2) // calling a function with an omitted name
32 Likes