[swift-evolution] Proposal: Allow operators to have parameters with default values

Brent Royal-Gordon brent at architechies.com
Sat Nov 4 01:55:26 CDT 2017


> On Nov 2, 2017, at 7:05 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Firstly, because for the proposed use case it's not a "default" parameter in that it's not overridable: you can't actually pass another argument.


Sure you can. Remember, you can call an operator with function-call syntax:

	(+)(1, 2)

We could allow you to specify the non-default parameters when you need to using this syntax:

	// Normal use:
	value !! MyError.missingValue

	// With defaulted parameters changed:
	(!!)(value, MyError.missingValue, file: someFile, line: someLine)

We could also—as part of a separate proposal, perhaps in a future version of Swift—explore a more elegant syntax for adding options to operator calls. This could be useful for things like string comparisons where you need to decide whether a comparison should be locale-aware, case-sensitive, etc.

	// Strawman syntax of possible future expansion:
	value !! MyError.missingValue #(file: someFile, line: someLine)

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171103/ded63a52/attachment.html>


More information about the swift-evolution mailing list