Jump to page: 1 210  
Page
Thread overview
Operator overloading.
Aug 14, 2001
John Fletcher
Aug 14, 2001
Walter
Aug 15, 2001
John Fletcher
Aug 15, 2001
Walter
Aug 16, 2001
John Fletcher
Aug 16, 2001
Rolf Campbell
Aug 16, 2001
Jonathan Cano
Aug 17, 2001
Carlo E. Prelz
Aug 17, 2001
Charles Hixson
Aug 17, 2001
Walter
Aug 18, 2001
Walter
Oct 29, 2001
Sean L. Palmer
Oct 30, 2001
Walter
May 02, 2002
John English
Aug 23, 2001
Roland
May 02, 2002
John English
May 06, 2002
Walter
May 06, 2002
Pavel Minayev
May 06, 2002
OddesE
May 08, 2002
John English
May 08, 2002
Russ Lewis
May 09, 2002
Roberto Mariottini
May 09, 2002
OddesE
May 09, 2002
Russ Lewis
Aug 17, 2001
Brendan McCane
Sep 09, 2001
Anthony Steele
Sep 10, 2001
Charles Hixson
Sep 10, 2001
Axel Kittenberger
Sep 10, 2001
Charles Hixson
Re: Operator overloading. (Partially)
Sep 10, 2001
Charles Hixson
Sep 10, 2001
Axel Kittenberger
Sep 10, 2001
Charles Hixson
Sep 11, 2001
Axel Kittenberger
Feb 04, 2002
timeless
Sep 11, 2001
a
Sep 11, 2001
Charles Hixson
Sep 12, 2001
a
Sep 12, 2001
Charles Hixson
Aug 17, 2001
kaffiene
Aug 17, 2001
John Fletcher
May 03, 2002
John English
Aug 18, 2001
kaffiene
Aug 19, 2001
kaffiene
Aug 20, 2001
Sheldon Simms
Aug 20, 2001
kaffiene
Aug 21, 2001
Charles Hixson
Aug 21, 2001
kaffiene
Aug 22, 2001
Charles Hixson
Aug 22, 2001
kaffiene
Aug 22, 2001
kaffiene
Aug 22, 2001
kaffiene
Operator overloading... an idea
Aug 26, 2001
Eric Gerlach
Aug 26, 2001
Walter
Aug 28, 2001
Eric Gerlach
Aug 30, 2001
Walter
Aug 28, 2001
Eric Gerlach
Sep 06, 2001
Russell Borogove
Sep 06, 2001
Charles Hixson
Aug 27, 2001
Charles Hixson
Aug 28, 2001
Eric Gerlach
Aug 22, 2001
Angus Graham
Aug 22, 2001
Kent Sandvik
Aug 23, 2001
kaffiene
Aug 23, 2001
Arjan Knepper
Aug 24, 2001
Walter
Aug 24, 2001
Dan Hursh
Aug 24, 2001
Charles Hixson
Oct 29, 2001
Sean L. Palmer
Nov 02, 2001
Walter
Nov 05, 2001
Roland
Nov 05, 2001
Axel Kittenberger
Nov 05, 2001
Juarez Rudsatz
Nov 05, 2001
Sean L. Palmer
Aug 17, 2001
Charles Hixson
Aug 18, 2001
kaffiene
Aug 21, 2001
Charles Hixson
Aug 21, 2001
kaffiene
May 03, 2002
John English
May 05, 2002
OddesE
Aug 18, 2001
Tim Sweeney
Aug 19, 2001
a
Aug 22, 2001
Dan Hursh
August 14, 2001
Quote from the specification for D:

Operator overloading. The only practical applications for operator overloading seem to be implementing a complex floating point type, a string class, and smart pointers. D provides the first two natively, smart pointers are irrelevant in a garbage collected language.

Another quote:

 D has many features to directly support features needed by numerics
programmers, like direct support for the complex data type and defined
behavior for NaN's and infinities.


Comment:

For numerical computing it is convenient to define classes e.g. vectors, matrices and other entities beyond complex numbers, such as quaternions.  For this overloading of operators such as +, -, +=, etc means that top level code can be easily written and readable.

John Fletcher


August 14, 2001
I agree that operator overloading can be used for matrix and vector classes, in fact, the first user of my C++ compiler used it to develop a matrix class! The results were disappointing, though. It's amazingly difficult to write a good class that overloads operators.

What's a quaternion? 4 reals?

-Walter

John Fletcher wrote in message <3B78E154.BC62E006@aston.ac.uk>...
>Quote from the specification for D:
>
>Operator overloading. The only practical applications for operator overloading seem to be implementing a complex floating point type, a string class, and smart pointers. D provides the first two natively, smart pointers are irrelevant in a garbage collected language.
>
>Another quote:
>
> D has many features to directly support features needed by numerics
>programmers, like direct support for the complex data type and defined behavior for NaN's and infinities.
>
>
>Comment:
>
>For numerical computing it is convenient to define classes e.g. vectors, matrices and other entities beyond complex numbers, such as quaternions.  For this overloading of operators such as +, -, +=, etc means that top level code can be easily written and readable.
>
>John Fletcher
>
>


August 15, 2001

Walter wrote:

> I agree that operator overloading can be used for matrix and vector classes, in fact, the first user of my C++ compiler used it to develop a matrix class! The results were disappointing, though. It's amazingly difficult to write a good class that overloads operators.
>
> What's a quaternion? 4 reals?
>
> -Walter
>

A quaternion is an object which has four components.  One is real.  The other three can be viewed as three mutually perpendicular imaginary numbers.  They were invented by Hamilton in the 1850's or thereabouts (before vectors) and now have a lot of use calculating rotations in three dimensions.

See for example "SymbolicC++, An introduction to Computer Algebra using object oriented programming" T.K. Shi & W.H.Steeb

http://issc.rau.ac.za/symbolic/symbolic.html

who define a quaternion class.

I use this software with DM compiler, making extensive use of templates and operator overloading, so that the top level program resembles as far as possible the algebra which is written down.  You can see some the results of this in http://www.ceac.aston.ac.uk/clifford/paper25/index.htm

It is difficult to write operator overloading classes well. I have used as a basis the work of Coplien.  Some of the issues are around the creation of temporary copies along the way.  I quite frequently have to extend the stack space to large values to get the programs to run.  That is the attraction of a language with garbage collection.

John Fletcher


August 15, 2001
Wow! I see what you're doing now.

"John Fletcher" <J.P.Fletcher@aston.ac.uk> wrote in message news:3B7A3FCB.DD2550E7@aston.ac.uk...
>
>
> Walter wrote:
>
> > I agree that operator overloading can be used for matrix and vector
classes,
> > in fact, the first user of my C++ compiler used it to develop a matrix class! The results were disappointing, though. It's amazingly difficult
to
> > write a good class that overloads operators.
> >
> > What's a quaternion? 4 reals?
> >
> > -Walter
> >
>
> A quaternion is an object which has four components.  One is real.  The
other
> three can be viewed as three mutually perpendicular imaginary numbers.
They
> were invented by Hamilton in the 1850's or thereabouts (before vectors)
and now
> have a lot of use calculating rotations in three dimensions.
>
> See for example "SymbolicC++, An introduction to Computer Algebra using
object
> oriented programming" T.K. Shi & W.H.Steeb
>
> http://issc.rau.ac.za/symbolic/symbolic.html
>
> who define a quaternion class.
>
> I use this software with DM compiler, making extensive use of templates
and
> operator overloading, so that the top level program resembles as far as
possible
> the algebra which is written down.  You can see some the results of this
in
> http://www.ceac.aston.ac.uk/clifford/paper25/index.htm
>
> It is difficult to write operator overloading classes well. I have used as
a
> basis the work of Coplien.  Some of the issues are around the creation of temporary copies along the way.  I quite frequently have to extend the
stack
> space to large values to get the programs to run.  That is the attraction
of a
> language with garbage collection.
>
> John Fletcher
>
>


August 16, 2001

Walter wrote:

> Wow! I see what you're doing now.
>

It was a related program which had the bug you found for me a little while ago.

John


August 16, 2001
Whether it is easy to write good overloaded operators or not doesn't remove the handiness of their existance.

How do you suggest matrix algebra be done in D?

Matrix a = matrixMult(matrixAdd(c, d), e);

or

Matrix a = c.add(d).mult(e);

???

Neither one of these is especially usefull for complex expresssions.

Also, another use for operator overloading is arbitrary presision Integers/Floats.

If I want a 128-bit or a 256-bit integer, I want to be able to use it in normal mathematical expressions.

-Rolf Campbell

"Walter" <walter@digitalmars.com> wrote in message news:9lbhub$20ib$1@digitaldaemon.com...
> I agree that operator overloading can be used for matrix and vector
classes,
> in fact, the first user of my C++ compiler used it to develop a matrix class! The results were disappointing, though. It's amazingly difficult to write a good class that overloads operators.
>
> What's a quaternion? 4 reals?
>
> -Walter
>
> John Fletcher wrote in message <3B78E154.BC62E006@aston.ac.uk>...
> >Quote from the specification for D:
> >
> >Operator overloading. The only practical applications for operator overloading seem to be implementing a complex floating point type, a string class, and smart pointers. D provides the first two natively, smart pointers are irrelevant in a garbage collected language.
> >
> >Another quote:
> >
> > D has many features to directly support features needed by numerics
> >programmers, like direct support for the complex data type and defined behavior for NaN's and infinities.
> >
> >
> >Comment:
> >
> >For numerical computing it is convenient to define classes e.g. vectors, matrices and other entities beyond complex numbers, such as quaternions.  For this overloading of operators such as +, -, +=, etc means that top level code can be easily written and readable.
> >
> >John Fletcher


August 16, 2001
Walter wrote:

> I agree that operator overloading can be used for matrix and vector classes, in fact, the first user of my C++ compiler used it to develop a matrix class! The results were disappointing, though. It's amazingly difficult to write a good class that overloads operators.

Just because something is difficult is no reason to exclude it from the language.  If we never allowed folks to attempt things that are difficult we'd never make any progress.  Operator overloading should definitely be in the language!


--
Jonathan Cano
Member of Technical Staff
MMC Networks, Inc.



August 17, 2001
John Fletcher wrote:

> Comment:
>
> For numerical computing it is convenient to define classes e.g. vectors, matrices and other entities beyond complex numbers, such as quaternions.  For this overloading of operators such as +, -, +=, etc means that top level code can be easily written and readable.
>
> John Fletcher

Gotta agree wholeheartedly with this. If you are doing any numerical computation, then using infix operators is an enormous convenience. This is one (only one, there are others:-) of the problems with Java IMO.

--
Cheers,

Brendan.
----------------------------------------------------------------------------
Brendan McCane                            Email:  mccane@cs.otago.ac.nz
Department of Computer Science            Phone:  +64 3 479 8588/8578.
University of Otago                       Fax:    +64 3 479 8529
Box 56, Dunedin, New Zealand.             There's only one catch - Catch 22.



August 17, 2001
Brendan McCane wrote:

> John Fletcher wrote:
>
> > Comment:
> >
> > For numerical computing it is convenient to define classes e.g. vectors, matrices and other entities beyond complex numbers, such as quaternions.  For this overloading of operators such as +, -, +=, etc means that top level code can be easily written and readable.
> >
> > John Fletcher
>
> Gotta agree wholeheartedly with this. If you are doing any numerical computation, then using infix operators is an enormous convenience. This is one (only one, there are others:-) of the problems with Java IMO.

Remember, from a distant perspective *all* "operators" are "syntactic sugar"! (A "convenience" as mentioned above.)

How's that?

Well, let's look at an arbitrary complex expression in C, one with several operators:

    this.that.pointer_to->something_else = z**(2*pi) / (x ^ 0xff);

Let's move it all to functions:

    memberOf(deRef(memberOf(memberOf(this, that),pointer_to)), something_else)
= div(pow(z, times(2, pi)), xor(x, 0xff));

Not a single operator in the line, and nearly completely unreadable.  (Should I have used RPN instead?)  Where to go from here?  Well, the isomorphism is visible, at the very least.  And that's the key.

Though I'm a D newbie, one resolution path comes from the separatiion of the syntactic and semantic elements of the language.  While pre-processing is not a "feature" of D, I'm sure some entreprising individuals will hack the parsers in a way that will allow arbitrary operator creation (and overloading), done under the guise of a simple mapping operation.  Of course, a tool such as M4 may be easier to use, or even cpp or sed!

For example, create the file "myoperators.d" with the following contents:

    import math;
    import operatorLib;

    Operator("**", <double LHS>, <double RHS>, "pow(LHS,RHS)");

    Overload("^", <double LHS>, <double RHS>, "pow(LHS,RHS)");

Then, in D code, do an "import myoperators".

The first definition would create the new operator "**", and the second would overload the "^" (XOR) operator for doubles.  (The assignment versions "**=" and "^=" could be implicitly defined whenever the LHS and RHS are of the same type.)  This would map expressions of the form "A**B" and "A^B" to the string "pow(A,B)" when A and B are doubles (where "LHS" and "RHS" are placeholder tokens for each side of the operator).  Once the code is generated, the compiler would catch type mismatch errors as usual.  Ideally, any such errors would be mapped back to the original text, and not to the replacement (a common problem with C macros).  Hence the need to hack the parsers (especially if things like operator precedence are to be implemented simply).  [Actually, I'd vote to eliminate multiple levels of operator precedence!  Let's make everything Left-to-Right, and use parens as needed to make precedence explicit.]

This could possibly be done via an enhanced module interface, allowing us to avoid many problems by simply forbidding operator definitions to be used within the files containing their definition.

I feel the many of the problems with (and objections to) C++ operator creation and overloading appear to reduce to management issues.  By making the process simpler and explicit (via implementation as a true dynamic language extension, rather than as a textual substitution) we may be able to control and manage the beast.  I'm not yet familiar enough with D and its parsers to make a specific recommendation.  Help?

Of course, Lisp and Forth adherents will point out the difficulties with "operator explosion", where so many custom operators are implemented that the language morphs into something quite implementation-specific, and completely impenetrable even to language experts.  Let's not make operator creation and overloading too easy!  But, within reasonable restrictions, it should be made possible.

How can we get what we need from operator creation and overloading with minimal fuss, safety, readability and reliability?  The C++ way has well documented difficulties and is easy to misuse, but it can be made to work.  Remember, D already provides overloading for the common math operators over the intrinsic numeric types.  Can we allow the D programmer to extend this on their own, or must the whole concept be scrapped?

If there really is no "suitable" way to do all this within D itself, then at least we'll always have functions and M4...


-BobC


August 17, 2001
Jonathan Cano wrote:
> 
> Just because something is difficult is no reason to exclude it from the language.  If we never allowed folks to attempt things that are difficult we'd never make any progress.  Operator overloading should definitely be in the language!

I think the problem here is to be able to balance the complexity you are inserting with the amount of real-life problems you are solving. Operator overloading implementation as a problem has been solved many times already.

I personally agree with Walter's decision: operators mean something very precise for me. For me, adding fancy meanings to them would just add to the confusion of the result.

Carlo

-- 
  *         Se la Strada e la sua Virtu' non fossero state messe da
parte,
* K * Carlo E. Prelz - fluido@fluido.as             che bisogno ci
sarebbe
  *               di parlare tanto di amore e di rettitudine?
(Chuang-Tzu)
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10