Try this:
Code: Select all
TYPE Point
POSSREP cartesian {X RATIONAL, Y RATIONAL}
POSSREP polar {R RATIONAL, THETA RATIONAL}
INIT
cartesian (R := SQRT(X * X + Y * Y), THETA := ATAN(Y / X))
polar (X := R * COS(THETA), Y := R * SIN(THETA));
The INIT section defines each POSSREP in terms of the value being selected. If you select a cartesian Point, it initialises the polar POSSREP from the cartesian Point. If you select a polar Point, it initialises the cartesian POSSREP from the polar Point.
NOTE: The above example depends on the OperatorsMath.d script having been loaded and executed from the Scripts directory. It defines SQRT, ATAN, COS, SIN, and many other math operators.
Here's an example of a type with three POSSREPs:
Code: Select all
TYPE Temperature
POSSREP Celsius {celsius RATIONAL}
POSSREP Kelvin {kelvin RATIONAL}
POSSREP Fahrenheit {fahrenheit RATIONAL}
INIT
Celsius (kelvin := celsius + 273.15, fahrenheit := (9.0 / 5.0) * celsius + 32.0)
Kelvin (celsius := kelvin - 273.15, fahrenheit := ((kelvin - 273.15) * (9.0 / 5.0)) + 32.0)
Fahrenheit (kelvin := (5.0 / 9.0 * (fahrenheit - 32.0) + 273.15), celsius := (5.0 / 9.0) * (fahrenheit - 32.0));