[swift-evolution] [Proposal] Set literal and Set type syntax

Howard Lovatt howard.lovatt at gmail.com
Tue Jan 19 19:56:05 CST 2016


The horse has probably bolted on this one, but in general array literals
can be confusing when used for anything other than an array. A compromise
position might be to remove the array literal `init` from `Set` and replace
it with a var arg `init`. It would break code, but not that much since
`Set` is new and a migration tool could find it easily. This gives:

    let sI = Set(1) // Set of Int
    let sAI = Set([1]) // Set of array of Int

On Wednesday, 20 January 2016, Greg Parker <gparker at apple.com> wrote:

>
> On Jan 18, 2016, at 2:55 PM, Howard Lovatt via swift-evolution <
> swift-evolution at swift.org
> <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>
> On Tuesday, 19 January 2016, Jack Lawrence <jackl at apple.com
> <javascript:_e(%7B%7D,'cvml','jackl at apple.com');>> wrote:
>
>
> On Jan 18, 2016, at 2:50 PM, Liam Butler-Lawrence via swift-evolution <
> swift-evolution at swift.org
> <javascript:_e(%7B%7D,'cvml','swift-evolution at swift.org');>> wrote:
>
>
> Set("a", "b", "c”) doesn’t compile. It currently has to be
>  Set(arrayLiteral: "a", "b", "c”). That said, I’d be satisfied with
> removing the external parameter name “arrayLiteral”. Not only is it
> unnecessary, but it’s confusing too: variadic parameters are not the same
> as an Array.
>
>
> init(arrayLiteral:) is there to satisfy ArrayLiteralConvertible. Set([“a”,
> “b”, “c”]) works just fine.
>
>
> Sure, but you could add another overload without the label.
>
>
> Only if you break existing code. Consider this expression:
>
>     Set(["a", "b"])
>
> Is this
> 1. a Set<String> with two elements "a" and "b"
> 2. a Set<Array<String>> with one element ["a", "b"]
>
> Currently it means #1. You could change it to mean #2, but that breaks
> existing code that expects #1. You could try to overload the no-name
> initializer, but that will be confusing to humans in some cases.
>
>
> --
> Greg Parker     gparker at apple.com
> <javascript:_e(%7B%7D,'cvml','gparker at apple.com');>     Runtime Wrangler
>
>
>

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


More information about the swift-evolution mailing list