> On 07 Apr 2016, at 19:16, Dave Abrahams via swift-evolution
> <[email protected]> wrote:
>
>> It would be nice to know the rationale behind the choice of the current
>> syntax.
>> I agree that these seem more natural:
>>
>> @warn_unused_result
>> public func ~=<I : ForwardIndexType where I : Comparable>(value: I,
>> pattern:
>> Range<I>) -> Bool
>>
>> @warn_unused_result
>> public func ~=<I : IntervalType>(value: I.Bound, pattern: I) -> Bool
>
> +1
This operator was firstly introduced in Swift in the form =~ but then it was
reversed to the current form (~3y ago). There’s a little context about this
change on Twitter: https://twitter.com/dmcrodrigues/status/717063623957471232
<https://twitter.com/dmcrodrigues/status/717063623957471232>.
>> I would not change from `~=` to `=~` though.
>
> One downside with `~=` is that it reads like `+=`, which mutates the
> LHS. Of course, `=~` has its own issues, e.g. `x=~y` might read as `x =
> ~y`.
I agree but this operator already exists in other languages like Ruby and Perl,
so align the syntax may be a good option.
> On 07 Apr 2016, at 18:56, Erica Sadun <[email protected]> wrote:
>
> I'd prefer to offer both ~= and =~, allowing the consumer to choose which
> side the pattern sits on.
On the other hand, I like in particular the option of having both `~=` and `=~`
to provide more flexibility like Erica has suggested. The main question is if
that’s ok introduce another operator in the language.
—
David
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution