[swift-evolution] Proposal: Python's "in" and "not in" syntactic sugar
Félix Cloutier
felixcca at yahoo.ca
Thu Dec 17 10:16:51 CST 2015
I don't like it because it introduces a second way to do something that's already quite easy.
It's impossible for the Swift compiler to enforce that people never create a `contains` method (or create it without adhering to whatever protocol `in` uses behind the scenes), so in my opinion this would increase the burden of creating types that feel first-class.
As it's already been said before, Swift has been very careful with keywords so far. I wouldn't be in favor of introducing a keyword that replaces a method call.
Félix
> Le 17 déc. 2015 à 10:48:02, Jeremy Pereira via swift-evolution <swift-evolution at swift.org> a écrit :
>
>
>> On 17 Dec 2015, at 15:59, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
>>
>>
>>> On Dec 17, 2015, at 9:51 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
>>>
>>>> if “hello” in [“hello, there”] { … }
>>>>
>>>> if “hello” not in [“hello, there”] { … }
>>>
>>> Swift is extremely sparing with keywords in operator position; the only ones I can think of off the top of my head are `is` and `as`, and even those aren’t actually operators. You’re proposing to introduce one as syntactic sugar for [array].contains(elem), and introduce an even more bizarre two-word operator for ![array].contains(elem). I don’t think that’s gonna fly.
>>
>> Most programmers would probably love using them though.
>
>
> If that’s the case, I’d be in the minority.
>
> I’d rather use [“hello", “there”].contains(“hello”). That might just be my background though which is heavily object oriented.
>
>>
>>>
>>> --
>>> Brent Royal-Gordon
>>> Architechies
>>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list