I am OK with (0 % m. n 0)'s giving 0, in accordance with J's properties
of 0. (0 ^ m. n 0) should likewise give 1.
(% m. n 0) is a different case. Should it return _? Can it be good
design to have a primitive whose whole purpose is to confine its range,
and then have it give a result that is out of range? Worse than that, a
result that loses precision on integers and requires conversions? I
don't see analogy to the real numbers as a sufficient argument; and the
fact that _ is not a number is particularly important when the range is
integers. Domain error seems the better solution, pending further
discussion.
(% m. 10 (2)) seems to me different altogether. Domain error is the
best way for the user to handle these exceptions.
BTW, in earlier J versions u :: v was pretty slow when u failed: the
code prepared for debugging, allocating blocks and formatting error
messages. As of J9.4 u :: v transfers directly to v when u fails, with
low overhead.
Henry Rich
On 4/27/2023 3:16 PM, Raul Miller wrote:
Hmm...
Looking at this, the domain errors do seem analogous to divide by zero errors.
So, in the context of %m.n, if we were being purely symmetric, a 0
result when both the numerator and denominator were effectively 0
would be the way to go, with an infinite result for the remaining
cases. (Infinity in modulo arithmetic seems a bit awkward, but I don't
have any better suggestions there.)
And, I suppose similar thinking might hold for monads?
Thanks,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm