-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-3550] Compound name syntax for functions with no params #46138
Comments
Huh. I thought f(🙂 was supported, but it's not. |
Let's see if I can double-escape this — you can use |
There was discussion about this but I can't remember where it landed. The "correct" name is |
Ambiguous? I think it would be unambiguously a function call 🙂 |
@DougGregor probably remembers where we ended up in this discussion. |
I thought we left it at "we don't have a good way to spell this, but it would be nice". |
Might I suggest, for parallels to `[:]` being an empty dictionary, `foo( : )`? It avoids `_` implying the presence of something discarded. |
The issue I have with |
...not in `[:]`? My thinking was, we've already got a precedent. `[]` means something other than an empty dictionary. Given that `["someKey": "someValue"]` is how a dictionary with one key-value pair is spelled, `[:]` is chosen to represent a dictionary with zero key-value pairs. By analogy, we've got a situation where `()` means something else (i.e. it invokes the function). Given that `foo(label: )` is how a function with one parameter is spelled, `foo( : )` can be how a function with zero parameters is spelled. It ain't perfect, but IMO it's not bad. Edit: how did you get this fudging thing to let you write () with : in it? |
Backslash before the colon. Code snippets are double-curly-braces. I'm pretty used to |
I think if we're inventing new syntax, swift-evolution needs a chance to bikeshed it. I don't personally like either of these options but I suppose I like |
Additional Detail from JIRA
md5: 9e54c0bcc3910a9a4c3dc549a118933b
relates to:
Issue Description:
The "compound name" of a function can be used to resolve ambiguities with argument labels, e.g.
foo(x:)
orfoo(_:)
. However, there's no such shortcut to specify an overload that has no arguments. A workaround is to use its type withas
:But it'd be nice to have some way of doing this without specifying the type. Perhaps
foo(_)
(for symmetry withfoo(_:)
)?The text was updated successfully, but these errors were encountered: