overloading operators for I/O

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Feb 14 23:37:08 PST 2007


Bill Baxter wrote:
> Walter Bright wrote:
>> Chad J wrote:
>>> Hmmmm, abstract algebra...
>>> would this be easily parsable?
>>> other objections?
>>> a = b (+) c;
>>> a = b (-) c;
>>> a = b (*) c;
>>> a = b (^) c;
>>> a = b (|) c;
>>> a = b ($) c;
>>> a = b (?) c;
>>> etc...
>>
>> Yes.
> 
> You mean yes on both counts?
> 
> It's kind of a controversial thing, I know, but for some types there 
> really are multiple ways to interpret basic operations.  Matlab, for 
> example, defines .* to mean element-wise multiplication and * to mean 
> matrix multiplication.  Both forms get plenty of use.  (Same for 
> exponentiation too -- .^ and ^ both exist).
> 
> I don't really care either way, but there is at least one example of a 
> widely used language, specifically for math, in which there are more 
> than the standard set of operators.
> 
> Also Ocaml or Haskell or one of those guys, I forget which, allows 
> definition of new operators using any combination of characters used in 
> the built-in operators.  E.g.  **+ or */* or +++ or +- can all be made 
> into custom operators.  I have to admit, /That/ one seems like a pretty 
> bad idea to me.  :-)

Cecil too. Didn't have a problem with it.

http://compilers.iecc.com/comparch/article/96-12-127


Andrei



More information about the Digitalmars-d mailing list