swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.76k stars 162 forks source link

Clarification of Which Pseudo-Functions May Be Provided as Arguments #237

Open tadbyt opened 10 months ago

tadbyt commented 10 months ago

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations#Special-Kinds-of-Methods

Description

Add a note in the Special Kinds of Methods subsection that enumerates the pseudo-functions that cannot be provided as an argument to a closure or function. If there are any that can, add additional notes or subsections equivalent to Operator Methods that provide the corresponding syntax and examples.

Motivation

In Swift, there are a number of features that are pseudo-functions. A pseudo-function is a feature that has most of the syntax and semantics of a function definition, but has a specific designated utilization. Examples of such features include computed property getters and setters, property observers, subscript getters and setters, and deinitializers. These may be considered to have a function type, ergo, could be passed to a closure or function as an argument.

In the Operator Methods subsection, an explicit statement is given that an operator whose definition satisfies that of a parameter’s type, may be given as an argument. It is unclear whether any pseudo-function could also be given as an argument and, if so, what the specific syntax would be. It would provide clarity to enumerate those that can be (and how) as well as those that can’t.

Alternatives Considered

None.