I know it's a bit late to the party but I have to disagree with the
The colon in the dictionary doesn't really separate names and values, it
separates values and values:
["something" + "else" : 1 + 2]
is a perfectly valid dictionary that doesn't read nor write anything by
name. In other words, there are no lhs-expressions there and that's ok.
We use = to rebind the names or, more generally, call setters, and when we
do this an lhs-expression is required, well, on the left side of an
assignment operator. This is in no way related to what happens with the
The situation is different with function parameters. We don't really pass a
dictionary; if we did, we'd use something like myFunc("":foo, "bar": baz)
as a syntax.
One can attempt to read the syntax as binding names that the function can
use as parameters, but this doesn't really work either: we only know the
parameter's external names and this binding doesn't "leak" into the
original scope. So if we are thinking about function call as an assignment,
then it should be in an extremely short-lived scope contained within a
function call. It doesn't look like this view will bring us any benefits.
I think it's best to imagine the colon in function calls as simply a third
punctuation symbol. We do need to select a simple, readily available symbol
that cannot be easily mixed with colon-inside-the-dictionary and
regular-assignment-symbol, yet is still instantly recognisable. Reusing the
colon is a reasonable compromise, although => would also work (and I wish
it was given serious consideration).
Though I agree that it seems a bit excessive to have a separate syntax for
On Sat, Feb 6, 2016 at 12:27 AM, Brent Royal-Gordon via swift-evolution < email@example.com> wrote:
This is perhaps a bit nitpicky, but I've noticed that Swift sometimes uses
colon to separate names and values, and sometimes uses equals. It's vaguely
What do I mean? Well, our language has this:
myFunc(foo, bar: baz)
But it also has:
@available(iOS, introduced=7.0, deprecated=8.0)
You create a dictionary like this:
let dict = ["key": "value"]
But you set it like this:
dict["key"] = "value"
Is there some principle here? The @available case seems particularly
strange to me, because those values read strongly like parameters to me.
swift-evolution mailing list