Adding Unicode operators to D

davidl davidl at 126.com
Thu Oct 23 03:21:18 PDT 2008


在 Thu, 23 Oct 2008 09:36:29 +0800,Steven Schveighoffer <schveiguy at yahoo.com> 写道:

> "Andrei Alexandrescu"  wrote
>> Correx:
>>
>> http://www.reddit.com/r/programming/comments/78rmc/allowing_unicode_operators_in_d_similarly_to/
>>
>> Andrei
>>
>
> No thanks.  Please let's only use operators that are on the keys of my
> keyboard. I don't fancy having to type key digraphs or trigraphs to try and
> write code.
>
> I understand that others already have this problem, but I don't.  This would
> be a huge detractor from D for me.  I'd definitely support a language fork
> at that point, or at least refuse to deal with any code that has unicode
> operators.  I think you'd find others feel the same way.
>
> Why can't the emacs module solution work that was used for the cheverons?
> That is, when emacs sees:
>
> x opCross(y);
>
> display it as
>
> x x y
>
> (of course, assume the middle x is the cross symbol, I have no idea how to
> type it).
>
> And upon save, regenerate the correct code.
>
> I see no issue with something like that.  This is all the compiler is doing
> anyways...
>

Everything you worry about is just poor editor. Why do you think an editor can affect the language?
And It complexes the language, if it's not priorly converted by the programmer. Also it possibly sets up 
future restrictions of extending the language in the correct direction! 
In your case: x opCross(y) , why identifier opCross(identifier) is considered as identifier x identifier?
So would the typical operator overload function declaration should be considered that way?

x opCross(y)
{
}

x x y
{
}

or even 

x opCross(y, m){} 

--->

x x y, m  {}

also consider a template declaration

Matrix opCross(T)(T a)
{
}

should it be considered as Matrix x T (T a)?

If not , how do you distinguish in all those circumstances(and not all possible "shouldn't be" situations are listed here)


> Note that any operators for unicode would be user-defined anyways, the
> standard operator symbols already cover what actually gets generated to
> machine code.  That is, unicode operator X is invariably going to map to
> opX, so there is no benefit to the compiler performing this step instead of
> an editor.
>
> -Steve
>
>
> 




More information about the Digitalmars-d-announce mailing list