On Friday, 1 March 2013 at 21:52:00 UTC, Paul D. Anderson wrote:
Operator overloading in D is straightforward and sensible.
I think there is an opportunity for D to do better with some
very small changes.
I propose including additional Unicode mathematical symbols as
recognized operators for opBinary. All that would be required
is to extend the lexer to recognize the symbols as binary
operators.
For example, in vector arithmetic there are two different
products defined -- the dot product and the cross product. Most
implementations I've seen overload '*' for the inner product,
but omit operator for the cross product. In UTF-8 the "middle
dot", ('•', \u00B7) and "multiplication sign", ('×', \u00D7),
correspond to the more usual mathematical notation for the dot
and cross products, respectively.
UTF-16 has many more mathematical symbols, particularly on the
2200-22FF and 2A00-2AFF code pages. \u2207 is a wedge, commonly
used for outer products. The circled plus (u\2A01) and circled
times sign (\2A02) are defined for some mathematical
operations. \u2A33 is the "smash product" symbol, which I've
never heard of before but it sounds cool.
Pros:
1. Extends the capability to define mathematical operators for
user-defined types
2. Shouldn't break any existing code since the symbols aren't
valid chars in identifiers (as far as I can tell) and aren't
being used elsewhere.
3. Takes advantage of the existing opBinary overloading so
implementation should be straightforward.
Cons:
1. They are hard to type or otherwise enter in to a text file.
2. They may not display correctly in some output forms.
3. They could be confusing to someone unfamiliar with the
concept.
In windows (x86, could include dos & linux?) you can hold down
the alt key and manually type in the value of the character; But
it seems to truncated to 8 bits so Alt+321 = 65 which is A, so
likely unless you're copy/pasting the symbols it probably won't
work.
With regard to the difficulty of entering or displaying these
characters, I think that is largely because modern computer
languages only give lip service to Unicode -- code is almost
exclusively written in ASCII. I have seen one instance where a
certain mathematical constant was named '?', but the author was
an iconoclast and pariah.
Those operators seem more useful for scientific math. I wouldn't
want them added to to the core language though.
ASCII can be typed with (almost) any keyboard and use any editor
(new or old); You can still read source code if outputted to a
dumb terminal rather than getting odd symbols (whitespace as
well) and may be tearing your hair out wondering what this UTF-8
symbol is or what it means.