This is a late addition to a language that started out with no such
facility at all, apart from the awkward GENERIC keyword. Most new
languages have a feature along these lines, but not the same. There are
keyword parameters with default values, for example. There is
overloading, and there is the feature that Ada calls “generic” and C++
calls “templates”. Or you can simply use pointers/locators that may have
the value null/nil. Swift has all of these, but also allows ordinary
parameters, not merely locators, to have the value nil. For example:
func doSomething(a: Int, b: Int, c: Int = 4) {
...
}
or:
func doSomething(a: Int, b: Int) {
/* 2-argument version */
}
func doSomething(a: Int, b: Int, c: Int) {
/* 3-argument version */
}
or:
func doSomething(a: Int, b: Int, c: Int?) {
if let c_verified = c {
realDoSomething(a, b, c_verified)
} else {
realDoSomething(a, b, 4)
}
}
--
John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
-- Charles Williams. "Taliessin through Logres: Prelude"