[swift-evolution] define backslash '\' as a operator-head in the swift grammar
Nicolas Fezans
nicolas.fezans at gmail.com
Tue Feb 7 11:32:10 CST 2017
As long as you don't impose to have at list a space between operators and
identifiers you need to be able to split something like
a+b into an identifer called "a" followed by an operator "+" itself
followed by an identifier "b"
In principle we could think of using a way to delimiter an operator name we
could have very expressive operator name. Imagine for instance using
\(relativelyFreeOperatorName) outside a string literal defined as a valid
operator, then you could write
a\(relativelyFreeOperatorName)b
without any problem. This is actually quite appealing to me, knowing that
at some point, if the operator name becomes very long it seems relatively
pointless to me to define it as an operator and not simply as a function.
Nicolas
On Tue, Feb 7, 2017 at 3:23 PM, Derrick Ho via swift-evolution <
swift-evolution at swift.org> wrote:
> I have found it strange that operator characters are the only ones that
> may be used as operators. Sometimes Characters that look like operators are
> not.
>
> Why does there need to be a divide?
>
> Why can't an arbitrary set of characters become operator-ized?
>
> For example some people would like "and" to become a binary operator and
> use it instead of "&&"
>
> If we had the ability to define an operator out of any set of characters I
> think it would make the swift language a lot better.
>
> Is there a technical reason why?
>
>
>
> On Tue, Feb 7, 2017 at 2:36 AM David Hart via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> And the overjoyed operator: \o/
>>
>> On 7 Feb 2017, at 08:04, Slava Pestov via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> I really have nothing to add to this discussion, except for this fun
>> fact: apparently, the backslash was added to ASCII so you could write /\
>> and \/ operators: http://www.bobbemer.com/BACSLASH.HTM
>>
>> Slava
>>
>> On Feb 5, 2017, at 7:29 AM, Nicolas Fezans via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> Dear all,
>>
>> This is a rather simple proposal to add '\' (backslash character) as a
>> valid operator-head in the swift grammar.
>>
>> One argument for it, is that there exist a backslash operator in the
>> MATLAB/Scilab/Octave languages. In this languages A\B solves the linear
>> system A*X = B for X (or the least square problem associated to it if the
>> system of equations is overdetermined). I am doing some numerical
>> computation in Swift and it would be nice to be able to declare the same
>> operator name for this functionality.
>>
>> I might have missed some arguments for not adding them, but I seems to me
>> that until now the \ character is only used inside of string literals. If
>> that is the case, both uses should never generate a conflict or be
>> ambiguous, isn't it? (String literals keep their interpretation of \ and \
>> used otherwise within the swift code will be interpreted as an operator or
>> as the beginning of an operator)
>>
>> I am curious to see what will be the feedback on this.
>>
>> Nicolas
>> _______________________________________________
>> 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
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170207/e6aae202/attachment.html>
More information about the swift-evolution
mailing list