Hi John, it's great to hear from you.
On 2025-12-01 03:11 -0500, John Cowan wrote:
> #90: The logic behind the R6RS redefinition of real? came from the Racket
> team, and one of them did write it up in an email. The idea is that a
> complex number should be considered real only if its imaginary part is
> exactly zero, as an inexact zero may be the result of a floating-point
> rounding error. Tests of the Racket corpus showed that only a handful of
> programs depended on the R5RS behavior.
I don't know where to find that email, but I finally went through
the R6RS rationale[1] to see how they justified the new semantics:
> R5RS creates a more insidious problem by defining (real? z) to be
> true if and only if (zero? (imag-part z)) is true. This means, for
> example, that -2.5+0.0i is real. If -2.5+0.0i is represented as a
> compnum, then the compiler cannot rely on x being a flonum in the
> consequent of (if (real? x) <expression1> <expression2>). This
> problem could be fixed by writing all of the arithmetic operations
> so that any compnum with a zero imaginary part is converted to a
> flonum before it is returned, but that merely creates an analogous
> problem for compnum arithmetic, as explained below. R6RS adopted
> a proposal by Brad Lucier to fix the problem: (real? z) is now true
> if and only if (imag-part z) is an exact zero.
My first thoughts on reading this paragraph were (a) they call
their example a problem without telling us whether this really *is*
a significant analysis problem for actual compilers, and (b) they
are talking about using 'real?' to distinguish between flonums &
compnums, rather than between real numbers & complex numbers. Is
that actually the right way to think about 'real?'? Or did they
blithely turn a numerical predicate into a numerical *representation*
predicate?
(Clearly Brad Lucier is someone to talk to about this. I had no
idea he was the guy behind the change.)
Regards & best wishes,
Wolfgang
[1]
https://www.r6rs.org/final/html/r6rs-rationale/r6rs-rationale-Z-H-2.html#node_toc_node_sec_11.6.6.2
--
Wolfgang Corcoran-Mathe <
w...@sigwinch.xyz>