Re: Operator overloading
Cory Wright <[email protected]> Sun, 16 Mar 2003 09:36:54 -0500
| Newsgroups | gmane.comp.lang.moto.devel |
|---|---|
| Organization | Stand Blue Technology |
| Message-ID | <[email protected]> |
On Sun, Mar 16, 2003 at 12:36:00PM +0000, Stefano Corsi wrote: > Overloaded operators could be implemented as functions or methods that take > operands as parameters and return a value. > So we modify the code for M_FUNCTION_DECLARATION and M_FUNCTION_DECLARATOR > case labels in mxcg.c to set a proper function name in case the function or > method is an operator. Characters as "+ - += -= []" etc... should not be part > of a function name, so we have to find a sustitute name for them (plus, > minus, pluseq, etc...) We should modify also mfn_symbolName mfn.c for > handling operator functions and methods. I like how Python handles this, with a special set of __*__ methods. For example, __add__() is used to create a '+' operator for an object, and __mul__ for mulitplication. Here is an example: http://vsbabu.org/mt/archives/2002/02/20/sample_script_operator_overloading.html Thats not a complete list, but I can't seem to find a good list anywhere on the net of the special __*__ methods that Python lets you overload. So to combine your suggestions there could be something like this: __plus__ + __minus__ - __equals__ == __pluseq__ += Cory -- Cory Wright Stand Blue Technology http://www.standblue.net/