July 03, 2013
On Wednesday, 3 July 2013 at 13:24:41 UTC, monarch_dodra wrote:
> Technically, + is already 1D matrix addition [..]

Not 1D matrix, but rather, 1x1 matrix.
July 03, 2013
On Wednesday, 3 July 2013 at 14:03:20 UTC, TommiT wrote:
> On Wednesday, 3 July 2013 at 13:24:41 UTC, monarch_dodra wrote:
>> Technically, + is already 1D matrix addition [..]
>
> Not 1D matrix, but rather, 1x1 matrix.

Sorry, didn't realize you were talking about:
sum[] = values[] + values[];
July 03, 2013
On Wednesday, 3 July 2013 at 12:45:53 UTC, TommiT wrote:
> On Wednesday, 3 July 2013 at 12:24:33 UTC, Wyatt wrote:
>> On Tuesday, 2 July 2013 at 22:28:24 UTC, TommiT wrote:
>>> On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
>>>> On 7/2/2013 1:47 PM, TommiT wrote:
>>>>> Division operator for strings doesn't make any sense,
>>>>
>>>> That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code. The classic example of this is the overloading of << and >> for stream operations in C++.
>>>
>>> I've never thought of it like that. At some point I remember writing a vector type which overloaded its binary * operator to mean dot product (or cross product, I can't remember). So, you can overload an operator, but you can't overload the meaning of an operator.
>>
>> This is something I was discussing with a friend recently, and we agreed it would be cool if there were set of operators with no definition until overloaded, so you could use e.g. (.) for dot product, (*) for cross product, (+) (or maybe [+]?) for matrix add, etc. instead of overloading things that already have specific, well-understood meaning.
>>
>> -Wyatt
>
> I don't see why we couldn't add the actual unicode ∙ and × characters to the language, make them operators and give them the fixed meaning of dot product and cross product respectively.
>
> Wouldn't + be the correct operator to use for matrix addition. What happens when matrices are added is quite different from when real values are added, but the meaning of + is still addition for the both of them.

Time to bring back those old APL keyboards - we can have a lot more symbols then ;-)

MP
July 03, 2013
On Wednesday, 3 July 2013 at 14:03:20 UTC, TommiT wrote:
> On Wednesday, 3 July 2013 at 13:24:41 UTC, monarch_dodra wrote:
>> Technically, + is already 1D matrix addition [..]
>
> Not 1D matrix, but rather, 1x1 matrix.

in conjunction with [] you have 1D addition. e.g.

	int[10] a = 1;
	int[10] b = 2;

	int[10] c = a[] + b[];

	foreach(el_c; c)
		assert(el_c == 3);
July 03, 2013
I am strongly against this kind of thing. Operator overloading is a very useful tool for providing obvious semantics to types. User defined data structures, like a matrix type, can be treated like first class citizens, just like built in primitive types, by having overloads for relevant operators.

Using an operator to implement something non-obvious is a crime to me. Plus, it's usually wrong, because like C++ streams, you'd have to have each binary relation take a reference to something (like an ostream) and return the reference again so you can chain the operators. Why chain several binary function calls together when you can have a single n-ary function call like std.path.buildPath?

Also to shamelessly self-plug, I made a garbage collected matrix type with a few overloads for fun recently. Maybe somebody will find a use for it. https://github.com/w0rp/dmatrix/blob/master/matrix.d
July 03, 2013
On Wed, Jul 03, 2013 at 11:48:21PM +0200, w0rp wrote:
> I am strongly against this kind of thing. Operator overloading is a very useful tool for providing obvious semantics to types. User defined data structures, like a matrix type, can be treated like first class citizens, just like built in primitive types, by having overloads for relevant operators.

Operator overloading was initially intended to support user-defined arithmetic types in a transparent way. However, the ability to attach Turing-complete semantics to an operator (for the purpose of implementing arithmetic) led to the temptation to assign *arbitrary* semantics to it. Which leads to (IMO) poor choices like operator<< and operator>> in C++'s iostream.


> Using an operator to implement something non-obvious is a crime to me. Plus, it's usually wrong, because like C++ streams, you'd have to have each binary relation take a reference to something (like an ostream) and return the reference again so you can chain the operators. Why chain several binary function calls together when you can have a single n-ary function call like std.path.buildPath?

+1. Especially given how nicely D has solved the problem of type-safe variadics.


> Also to shamelessly self-plug, I made a garbage collected matrix type with a few overloads for fun recently. Maybe somebody will find a use for it. https://github.com/w0rp/dmatrix/blob/master/matrix.d

I think this is a clear sign that we need *some* kind of linear algebra / multidimensional array support in Phobos. Denis Shelomovskij and myself have independently implemented generic n-dimensional array libraries, of which 2D arrays are a special case. Your matrix implementation is the 3rd instance that I know of. There are probably more.

Though, matrix types and 2D arrays probably will want to overload opBinary!"*" differently (matrix multiplication vs. per-element multiplication, for example). In theory, though, a matrix type can just wrap around a 2D array and just override / provide its own opBinary!"*".


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius
July 05, 2013
On Tuesday, 2 July 2013 at 23:28:41 UTC, monarch_dodra wrote:
> On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
>> On 7/2/2013 1:47 PM, TommiT wrote:
>>> Division operator for strings doesn't make any sense,
>>
>> That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code.
>
> s/division/"The common agreed upon semantic"/
>
>> The classic example of this is the overloading of << and >> for stream operations in C++.
>
> Or overloading ~ to mean "concat" ?

It's rather C++'s std::string which overloads the meaning of + to mean "concatenation". I wonder if some other programming language has assigned some other symbol (than ~) to mean "concatenation". I guess math uses || for it.
July 05, 2013
Am 05.07.2013 16:59, schrieb TommiT:
> On Tuesday, 2 July 2013 at 23:28:41 UTC, monarch_dodra wrote:
>> On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
>>> On 7/2/2013 1:47 PM, TommiT wrote:
>>>> Division operator for strings doesn't make any sense,
>>>
>>> That's why overloading / to do something completely unrelated to
>>> division is anti-ethical to writing understandable code.
>>
>> s/division/"The common agreed upon semantic"/
>>
>>> The classic example of this is the overloading of << and >> for
>>> stream operations in C++.
>>
>> Or overloading ~ to mean "concat" ?
>
> It's rather C++'s std::string which overloads the meaning of + to mean
> "concatenation". I wonder if some other programming language has
> assigned some other symbol (than ~) to mean "concatenation". I guess
> math uses || for it.

Visual Basic uses &
Perl and PHP use  .
Ocaml uses        ^

Just from the top of my mind, surely there are other examples.

--
Paulo
July 05, 2013
On Friday, 5 July 2013 at 15:04:44 UTC, Paulo Pinto wrote:
> Am 05.07.2013 16:59, schrieb TommiT:
>> On Tuesday, 2 July 2013 at 23:28:41 UTC, monarch_dodra wrote:
>>> On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
>>>> On 7/2/2013 1:47 PM, TommiT wrote:
>>>>> Division operator for strings doesn't make any sense,
>>>>
>>>> That's why overloading / to do something completely unrelated to
>>>> division is anti-ethical to writing understandable code.
>>>
>>> s/division/"The common agreed upon semantic"/
>>>
>>>> The classic example of this is the overloading of << and >> for
>>>> stream operations in C++.
>>>
>>> Or overloading ~ to mean "concat" ?
>>
>> It's rather C++'s std::string which overloads the meaning of + to mean
>> "concatenation". I wonder if some other programming language has
>> assigned some other symbol (than ~) to mean "concatenation". I guess
>> math uses || for it.
>
> Visual Basic uses &
> Perl and PHP use  .
> Ocaml uses        ^
>
> Just from the top of my mind, surely there are other examples.
>
> --
> Paulo

So it's a mess, basically.
July 05, 2013
On Fri, Jul 05, 2013 at 05:04:46PM +0200, Paulo Pinto wrote:
> Am 05.07.2013 16:59, schrieb TommiT:
> >On Tuesday, 2 July 2013 at 23:28:41 UTC, monarch_dodra wrote:
> >>On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
> >>>On 7/2/2013 1:47 PM, TommiT wrote:
> >>>>Division operator for strings doesn't make any sense,
> >>>
> >>>That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code.
> >>
> >>s/division/"The common agreed upon semantic"/
> >>
> >>>The classic example of this is the overloading of << and >> for stream operations in C++.
> >>
> >>Or overloading ~ to mean "concat" ?
> >
> >It's rather C++'s std::string which overloads the meaning of + to mean "concatenation". I wonder if some other programming language has assigned some other symbol (than ~) to mean "concatenation". I guess math uses || for it.
> 
> Visual Basic uses &
> Perl and PHP use  .
> Ocaml uses        ^
> 
> Just from the top of my mind, surely there are other examples.
[...]

Python uses +.

Arguably, C uses blank (two string literals side-by-side are automatically concatenated), but that's a hack, and an incomplete one at that. :-P


T

-- 
Lawyer: (n.) An innocence-vending machine, the effectiveness of which depends on how much money is inserted.