[r6rs-discuss] [Formal] Clean-up in the additional arithmetic
alan at alan-watson.org
Tue Nov 14 19:50:57 EST 2006
This message is a formal comment which was submitted to formal-comment at r6rs.org, following the requirements described at: http://www.r6rs.org/process.html
Submitter: Alan Watson
Email address: alan at alan-watson.org
Issue type: Clarification and Enhancement
Report Version: Version: 5.91
Summary: Clean-up in the additional arithmetic libraries
Consistency and simplicity of naming is important, especially when
dealing with libratries that introduce variants on a common operation.
I propose the following renamings and additions to the arithmetic
libraries defined in section 16. These have the global advantage of
using exactly the same names for both generic and type-specific
procedures representing similar mathematical operations.
How then would one distinguish between different procedures with the
same name? One would use the renaming or prefixing procedures allowed by
the library system. For example, one would import the fixnum procedures
with a prefix of "fixnum:". This would give completely consistent names;
currently some of the current names are prefixed by "fixnum" and others
by "fixnum-", and some have an appended "?".
Library (r6rs arithmetic fixnum) is renamed as (r6rs arithmetic fixnum
quotient-ring) or (r6rs arithmetic fixnum modular).
All of these routines are synonums for the current "fixnum?".
Rationale: The generic routines use these procedures to discern types.
The fixnum specific routines should use the the same names. In this
context, "number?" means "Does the fixnum library treat this as a
Comment: Equivalent to the generic exact? and inexact?, but with the
arguments restricted for fixnums.
Comment: Fixnum to general inexact and general number to fixnum,
signalling if "no reasonable close equivalent".
Comment: "+" means something quite specific in arithmetic. The routine
"div+mod" should properly return the sum of the div and mod. With
"div-and-mod", this confusion does not arise.
Comment: The use of "/" to mean "with" is specific to only certain
dialects of English. It is not well know, for example, in British
English. Furthermore, "/" already has a specific meaning in
arithmetic; the procedure "+/carry" should return the sum divided by
Comment: These perform bitwise operations, not logical operations, and
should be marked as such. For example, using "bitwise-not" makes it
clear that the procedure corresponds to C's "~" operations not C's "!"
I suggest "or" instead of "ior" because "or" is already used in the
base library to mean inclusive or (albeit a logical inclusive or).
I suggest "exclusive-or" instead of "xor" because Scheme has
historically preferred to avoid abreviations. However, "xor" would not
Comment: This should be the same as:
(fixnum-copy-bit fx1 fx2 (fixnum-logical-shift-left 1 fx2))
Comment: "logical" in the context of Scheme seems to me to refer more
to booleans. I would suggest "bitwise-shift" here or, failing that,
just plain "shift".
Comment: Why is there no three-argument logical shift, to match the
three-argument arithmetic shift?
Library "(r6rs arithmetic fx)" is renamed "(r6rs arithmetic fixnum
Similar changes are made in the procedures.
In addition, I see no reason for omitting procedures simply because they
depend on the precision w, so I would add the carry procedures and the
logical shift procedures. The results are perfectly well defined,
although obviously they depend on w.
Comment: Generic number to flonum, yielding a NaN if the number is
complex, and flonum to generic exact number.
Comment: Even if you hate this idea, flcos is missing.
16.5 Exact arithmetic
By now, the pattern of my suggested renamings should be clear.
This library also needs:
along with appropriate additions corresponding to the added fixnum
16.6 Inexact arithmetic
Again, renamings to remove prefixes and spurious ? suffixes, along with:
More information about the r6rs-discuss