overloading operators for I/O
Bill Baxter
dnewsgroup at billbaxter.com
Wed Feb 14 22:58:12 PST 2007
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. :-)
--bb
More information about the Digitalmars-d
mailing list