digitalmars.D - operators
- james keogh (10/10) Aug 16 2004 one feature i have often wish for in a language is the ability to define...
- Garett Bass (19/29) Aug 16 2004 When I first learned of the operator overload syntax in C++ I was very
- james keogh (8/20) Aug 17 2004 matrix and vector operation would certainly be a strong candidate for th...
- Nick (11/15) Aug 17 2004 Firstly, like someone noted, most people wouldn't have a clue how to typ...
- Arcane Jill (9/13) Aug 17 2004 It's kind of already in use. When I implemented the Int class, I had to ...
- james keogh (9/20) Aug 18 2004 exactly is you want something other than the predefined operators it wou...
-
james keogh
(15/27)
Aug 18 2004
- teqDruid (5/18) Aug 17 2004 Yeah, but half the programmers using your class wouldn't know how to typ...
- james keogh (5/9) Aug 17 2004 true - we can make it the '€' character then to make it easier :-D
- Ilya Minkov (13/26) Aug 17 2004 One problem you have to consider is that the operator precedence has to=...
one feature i have often wish for in a language is the ability to define ne operators - to leep the code readable new operators would have to begin and or end with a reserved symbol i think. some thing like £operatorname for post operatorname£ for pre and £operatorname£ for binary operator. on the other hand perhaps i wont need this as much with d as there is a seperate concat operator to arithmetic which is where the feature is usually wanted in other languages to workout my email address firstname.lastname astrium.eads.net
Aug 16 2004
When I first learned of the operator overload syntax in C++ I was very excited, I immediately planned to write the following: class Vector { int operator·(Vector &other); // dot product Vector operator×(Vector &other); // cross product } You can imagine my disappointment when I discovered you can only overload the existing scalar math operators that are already part of the language. I thought the above would make some nice syntactic sugar for linear algebra code. Oh well :P "james keogh" <james_member pathlink.com> wrote in message news:cfq36a$24lb$1 digitaldaemon.com...one feature i have often wish for in a language is the ability to defineneoperators - to leep the code readable new operators would have to beginand orend with a reserved symbol i think. some thing like £operatorname for post operatorname£ for pre and£operatorname£for binary operator. on the other hand perhaps i wont need this as much with d as there is aseperateconcat operator to arithmetic which is where the feature is usually wantedinother languages to workout my email address firstname.lastname astrium.eads.net
Aug 16 2004
In article <cfqn3q$2kk0$1 digitaldaemon.com>, Garett Bass says...When I first learned of the operator overload syntax in C++ I was very excited, I immediately planned to write the following: class Vector { int operator·(Vector &other); // dot product Vector operator×(Vector &other); // cross product } You can imagine my disappointment when I discovered you can only overload the existing scalar math operators that are already part of the language. I thought the above would make some nice syntactic sugar for linear algebra code. Oh well :Pmatrix and vector operation would certainly be a strong candidate for this sort of thing. other less used arithmetic operators could become operators instead of functions perhaps we could persuade all those physicists still using fortran to switch if they were allowed a raise to the power of operator? to workout my email address firstname.lastname astrium.eads.net
Aug 17 2004
In article <cfshfj$tmd$1 digitaldaemon.com>, james keogh says...matrix and vector operation would certainly be a strong candidate for this sort of thing.Firstly, like someone noted, most people wouldn't have a clue how to type · or × (center dot and "x", do they even display correctly?) Secondly, it's a bad idea for the sake of readability to allow arbitrary operators with which readers have no previous experience. For example, which do you think is clearest? Tensor a, b; .. a = a &% b; a = a.tensorProd(b);perhaps we could persuade all those physicists still using fortran to switch if they were allowed a raise to the power of operator?You can use ^, opXor :-) Nick
Aug 17 2004
In article <cftr6i$1f82$1 digitaldaemon.com>, Nick says...It's kind of already in use. When I implemented the Int class, I had to use opXor() for, well, XOR. Basic and others use operator ** to mean "raised to the power of". It would be nice if D could introduce that. Its precedence is known (higher than *) and so is its associativity (not associative, evaluate right-to-left). Its override could be called opPow(). Just a thought. Arcane Jillperhaps we could persuade all those physicists still using fortran to switch if they were allowed a raise to the power of operator?You can use ^, opXor :-) Nick
Aug 17 2004
exactly is you want something other than the predefined operators it would be nice to beable to give it a different name - and something more meaningfull than a single char ie £pow£You can use ^, opXor :-) NickIt's kind of already in use. When I implemented the Int class, I had to use opXor() for, well, XOR.Basic and others use operator ** to mean "raised to the power of". It would be nice if D could introduce that. Its precedence is known (higher than *) and so is its associativity (not associative, evaluate right-to-left). Its override could be called opPow(). Just a thought. Arcane Jillhmm, must admit i hadnt thought about operator precedence when defining new operators. either youd need some way of stating what the precedence was for your operator or youd have to have all user defined operators at the same precedence which would then require lots of () to get expressions correct to workout my email address firstname.lastname astrium.eads.net
Aug 18 2004
In article <cftr6i$1f82$1 digitaldaemon.com>, Nick says...In article <cfshfj$tmd$1 digitaldaemon.com>, james keogh says...<snip> i think you are missing the point the operator you would write would not be a meaniningless symbol but something like d = a £foo_op£ b £foo_op£ c (i know £ isnt a good char for the begin/end op name but it shows the intent) this would be better than d = (a.foo_op(b)).foo_op(c) to my mind anyway - you also distinguish between differt unary and binary ops easily b= pre_op£a b= a£post_op c= a £bin_op£ c to workout my email address firstname.lastname astrium.eads.netmatrix and vector operation would certainly be a strong candidate for this sort of thing.Firstly, like someone noted, most people wouldn't have a clue how to type · or × (center dot and "x", do they even display correctly?) Secondly, it's a bad idea for the sake of readability to allow arbitrary operators with which readers have no previous experience. For example, which do you think is clearest? Tensor a, b; .. a = a &% b; a = a.tensorProd(b);
Aug 18 2004
On Mon, 16 Aug 2004 10:44:26 +0000, james keogh wrote:one feature i have often wish for in a language is the ability to define ne operators - to leep the code readable new operators would have to begin and or end with a reserved symbol i think. some thing like £operatorname for post operatorname£ for pre and £operatorname£ for binary operator.Yeah, but half the programmers using your class wouldn't know how to type the £ character, and would have to copy-paste it out of the documentation like I just did out of your post. :)on the other hand perhaps i wont need this as much with d as there is a seperate concat operator to arithmetic which is where the feature is usually wanted in other languages to workout my email address firstname.lastname astrium.eads.net
Aug 17 2004
Yeah, but half the programmers using your class wouldn't know how to type the £ character, and would have to copy-paste it out of the documentation like I just did out of your post. :)true - we can make it the '€' character then to make it easier :-D there must be some character that isnt already a symbol and is on most keyboards to workout my email address firstname.lastname astrium.eads.net
Aug 17 2004
One problem you have to consider is that the operator precedence has to=20 be solved in a parser someway. As it is now, it's solved by formulating=20 a grammar which solves the priorities implicitly. I'm afraid explicit=20 priority solving like is requiered for unforeseen operators, if they are = allowed to have different priorities anyway, would be somewhat brittle=20 and wouldn't fit well. -eye james keogh schrieb:one feature i have often wish for in a language is the ability to defin=e neoperators - to leep the code readable new operators would have to begin=and orend with a reserved symbol i think. =20 some thing like =A3operatorname for post operatorname=A3 for pre and =A3=operatorname=A3for binary operator. =20 on the other hand perhaps i wont need this as much with d as there is a=seperateconcat operator to arithmetic which is where the feature is usually wan=ted inother languages =20 to workout my email address firstname.lastname astrium.eads.net=20
Aug 17 2004