[swift-evolution] [Pitch] Allow trailing argument labels

Haravikk swift-evolution at haravikk.me
Wed Feb 22 07:03:56 CST 2017


> On 22 Feb 2017, at 11:48, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> On Feb 22, 2017, at 3:32 AM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 	foo.example(foo) // What did I mean here?
>> 	let result = foo.example(foo:) // This looks like I might be trying to select a function, rather than call it
> 
> I think it would be really weird to support not one, but *two* potentially ambiguous sugar forms.

Those aren't examples I think should be supported, I was thinking out loud. The point I was trying to make is that it's not the trailing nature that's a requirement, but that the real requirement for this feature to work is that there's at least one other, non-Void argument.


On another note, one other alternative I did think of for declaration is that perhaps it might be better still to use an attribute to specify a label-only "argument". Think of it like an attribute on the type, except that it specifies that there is no type:

	func adding(_ other:Self, reportingOverflow:@labelonly) { … }

The attribute makes it absolutely clear that this is just a label and not an actual, functional argument (there won't be a reportingOverflow local variable), and that it can be passed without a value when calling this method. It'll still need the trailing colon for possible disambiguation of variables though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170222/79a59a18/attachment.html>


More information about the swift-evolution mailing list