Thread overview
operators
Aug 16, 2004
james keogh
Aug 16, 2004
Garett Bass
Aug 17, 2004
james keogh
Aug 17, 2004
Nick
Aug 18, 2004
Arcane Jill
Aug 18, 2004
james keogh
Aug 18, 2004
james keogh
OT: Re: operators
Aug 17, 2004
teqDruid
Aug 17, 2004
james keogh
Aug 17, 2004
Ilya Minkov
August 16, 2004
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
August 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 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


August 17, 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

August 17, 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 :P

matrix 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
August 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 hows about # or @

to workout my email address firstname.lastname@astrium.eads.net
August 17, 2004
One problem you have to consider is that the operator precedence has to be solved in a parser someway. As it is now, it's solved by formulating a grammar which solves the priorities implicitly. I'm afraid explicit priority solving like is requiered for unforeseen operators, if they are allowed to have different priorities anyway, would be somewhat brittle and wouldn't fit well.

-eye

james keogh schrieb:

> 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 
August 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


August 18, 2004
In article <cftr6i$1f82$1@digitaldaemon.com>, Nick says...

>>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

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 Jill


August 18, 2004
In article <cftr6i$1f82$1@digitaldaemon.com>, Nick says...
>
>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);
>
<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.net
August 18, 2004

>>You can use ^, opXor :-)
>>
>>Nick
>
>It's kind of already in use. When I implemented the Int class, I had to use
>opXor() for, well,  XOR.

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£

>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 Jill

hmm, 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