How to merge required operations under a common name
Hello,
I am facing the following question when implementing the standard
document: May I implement separate required operations under a common name?
Examples:
(1) recip (x) could be provided by div (1, x).
(2) sqr (x) could be provided by pown (x, 2)
if pown is tightest for p = 2.
(3) numsToInterval (l, u) and textToInterval (s) could be provided
by an overloaded function “anyToInterval”.
(4) pown (x, p) and pow (x, y) could be provided
by an overloaded function “power” (with different semantics whether
the second parameter is an interval or not).
The reasons for this are that I do not want to pollute the namespace of
the host language with uncommon names, so that users can easily convert
their existing scripts into interval extensions and don't have to learn
new function names.
Would the standard allow this?
In examples (1) and (2) the operations could be interchanged easily.
In example (4) overloading adds the risk of addressing the wrong
operation without recognizing it, e. g.,
sqr (x) <-> pown (x, 2) <-> power (x, 2)
Now if we make an error and use interval [2, 2] instead of integer 2, we
would address pow (x, 2), which is defined for x > 0 only—in contrast to
the sqr operation.
Best regards
Oliver Heimlich