Operator overloading
Posted: Wed Sep 14, 2011 6:08 pm
I'm not exactly a "newbie" but I've been away from APL for about 15 years now and am looking into the new OOP APL capabilities.
One of the features of OOP in c++ and some other languages is providing methods that determine how class objects behave under primitive operations. For example, if I have a class that represents a Unit of measure (meter/second, kg/meter*3, etc.) and I want to be able to determine the resulting Unit when I multiply or divide Units. If it is possible to override the behavior of the primitive operators, like in c++, then I could write something like this
uom1 ← ⎕NEW Unit ('meter/second' ... other initializing args)
uom2 ← ⎕NEW Unit ('second' ... other initializing args)
uom3 ← uom1 × uom2
⎕←uom3.Name
meter
where the implementation of the operator× for the Unit class would know enough to be able to do units-cancellation to arrive at the right answer. I have written such operators in c++. I was wondering if the OOP implemention in APL allows one to do something similar?
One of the features of OOP in c++ and some other languages is providing methods that determine how class objects behave under primitive operations. For example, if I have a class that represents a Unit of measure (meter/second, kg/meter*3, etc.) and I want to be able to determine the resulting Unit when I multiply or divide Units. If it is possible to override the behavior of the primitive operators, like in c++, then I could write something like this
uom1 ← ⎕NEW Unit ('meter/second' ... other initializing args)
uom2 ← ⎕NEW Unit ('second' ... other initializing args)
uom3 ← uom1 × uom2
⎕←uom3.Name
meter
where the implementation of the operator× for the Unit class would know enough to be able to do units-cancellation to arrive at the right answer. I have written such operators in c++. I was wondering if the OOP implemention in APL allows one to do something similar?