On operators 
Author Message
 On operators

Quote:

> I discovered a couple of shortcomings in the functions I posted previously
> so I rewrote them.  They now correctly handle operations with scalers and
> should be a little faster when the arguments are already the same size.

> My preference is for The MathWorks to leave the use of the overloaded
> operators up to the user, but if you want to use them you can.  This
> version of minus.m can easily be modified for +, ./, etc.


> function z = minus(x,y)
> %MINUS Subtraction (overloads minus for doubles).
> %   X - Y returns the difference of X and Y.  X and Y must be the same size
> %   unless one of them is a scalar or they differ in only one dimension
> %   and that dimension is 1 for either X or Y in which case the data for
> %   that dimension is replicated appropriately.
> %
> %   For example,
> %       [1 2 3;4 5 6] - [100 200 300]
> %   is the same as
> %       [1 2 3;4 5 6] - [100 200 300;100 200 300]
> %   where the single row has been replicated.

Seems a bit strange. As pointed out, when do you get errors? What if
everyone had their own definition of minus - don't things become
impossible to port?

Another way is the APL/J approach - higher level
functions that operate on other functions. In this case rank:

   a=. 2 3$i. 6
   a
0 1 2
3 4 5
   b=. 100 200 300
   b
100 200 300
   a + b
length error

   a +"1 b
100 201 302
103 204 305

--
Sam Sirlin



Fri, 06 Apr 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. operator overloading and user definable operators.

2. Overloading logical operators and bitwise operators

3. OPERATOR (was: Why no ** operator in Modula2?)

4. Aliases for operators, creating new operators

5. Operator overload of base operator and compiler diagnostic

6. Is there a reverse operator to the '%' operator on string ?

7. Creating collections - dynamic list operator {...}

8. Creating collections - dynamic list operator - braces

9. NY/SIGAPL meeting 2/23/95: Brickman on Operators

10. Retrieving the name of defined operator operands

11. what does J operator #: do?

12. Triadic Operators in J?

 

 
Powered by phpBB® Forum Software