[swift-evolution] A path forward on rationalizing unicode identifiers and operators

Xiaodi Wu xiaodi.wu at gmail.com
Mon Oct 2 17:24:13 CDT 2017


On Mon, Oct 2, 2017 at 12:58 PM, David Sweeris <davesweeris at mac.com> wrote:

>
> On Oct 2, 2017, at 09:14, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> What is your use case for this?
>
> On Mon, Oct 2, 2017 at 10:56 David Sweeris via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>>
>> On Oct 1, 2017, at 22:01, Chris Lattner via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>
>> On Oct 1, 2017, at 9:26 PM, Kenny Leung via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> Hi All.
>>
>> I’d like to help as well. I have fun with operators.
>>
>> There is also the issue of code security with invisible unicode
>> characters and characters that look exactly alike.
>>
>>
>> Unless there is a compelling reason to add them, I think we should ban
>> invisible characters.  What is the harm of characters that look alike?
>>
>>
>> Especially if people want to use the character in question as both an
>> identifier and an operator: We can make the character an identifier and its
>> lookalike an operator (or the other way around).
>>
>
> Off the top of my head...
> In calculus, “𝖽” (MATHEMATICAL SANS-SERIF SMALL D) would be a fine
> substitute for "d" in “𝖽y/𝖽x” ("the derivative of y(x) with respect to
> x").
> In statistics, we could use "𝖢" (MATHEMATICAL SANS-SERIF CAPITAL C), as
> in "5𝖢3" to mimic the "5C3" notation ("5 choose 3"). And although not
> strictly an issue of identifiers vs operators, “!” (FULLWIDTH EXCLAMATION
> MARK) would be an ok substitution (that extra space on the right looks
> funny) for "!" in “4!” ("4 factorial").
>
> I'm sure there are other examples from math/science/<insert any
> "symbology"-heavy DSL here>, but “d” in particular is one that I’ve wanted
> for a while since Swift classifies "∂" (the partial derivative operator) as
> an operator rather than an identifier, making it impossible to use a
> consistent syntax between normal derivatives and partial derivatives
> (normal derivatives are "d(y)/d(x)", whereas partial derivatives get to
> drop the parens "∂y/∂x")
>

Allowing a custom operator that looks like `!` to be anything other than
the force-unwrap operator would be unwise, IMO, and not a desirable goal.
Likewise characters that look like `d` not being the character `d`, etc. In
the previous PR, the authors deliberately created a system where these will
not be possible.

I think we should specify from the outset of re-examining this topic that
supporting arbitrary math/science notation without demonstrable improvement
in code clarity for actual, Swift code is a non-goal. Since manipulating
matrices is a common programming task, and the current BLAS syntax is
terribly cumbersome, being able to use operators for matrix multiplication,
inversion, etc. is imminently reasonable. Having a way of writing
`4.factorial()` that looks like an equation in a math textbook, however,
wouldn't pass that bar.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171002/76130d7e/attachment.html>


More information about the swift-evolution mailing list