This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: SCM_VALIDATE_...
I'm coming in rather late on this discussion, so I may be missing the
point, but:
Within the interpreter, it's useful to have predicates that ask about
a number's *representation*, not its *value*. The Scheme-level
predicates only ask about numbers' values, never their
representations.
So we could have a set of predicates that ask about representations:
SCM_REP_FIXNUM_P
SCM_REP_FLOAT_P
SCM_REP_BIGNUM_P
...
and a set of predicates that ask about values (as the Scheme functions do):
SCM_INTEGER_P
SCM_RATIONAL_P
SCM_REAL_P
SCM_COMPLEX_P
...
SCM_EXACT_P
SCM_INEXACT_P
In general, I think user code really wants the latter set of
functions. We should have a value-oriented set of conversion
functions, named after the C type we're converting from or to, but
which treat all representations similarly:
scm_num2int
scm_num2long
scm_num2ulong
scm_num2double
...
scm_int2num
scm_long2num
scm_ulong2num
scm_double2num
...
The idea here is that the conversions succeed if a "true" conversion
is possible:
- conversions from Scheme objects to C integers work on any representation,
but fail if the value is non-integral, inexact, or doesn't fit
- conversions from C integers to Scheme numbers produce exact values,
using whatever representation is appropriate
I think this is more consistent with the way the rest of Scheme works.