[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why would anyone want opacity?



> Of course there are times when one needs such things.  My objection is
> to making generic numbers the *default*.  Most of the numbers in my
> programs are small integers, and I expect this to be true even in
> heavy generic math packages.  We can safely assume that loop indices,
> array subscripts, etc., are not quaternions most of the time.  And
> most of the numbers (at least in my programs) are loop indices of some
> sort.
>--------------------------------------------------------------------------

In MIT Scheme (and probably many other Scheme implementations as well),
there exists a full spectrum of non-generic primitive arithmetic operators,
such as:

     fix:+      fix:*      fix:-  ...  [fixnums: fixpoint integers]
     flo:+      flo:*      flo:-  ...  [flonums: floating point reals]
     int:+      int:*      int:-  ...  [bignums: multi-word integers + fixnums]
     rat:+      rat:*      rat:-  ...  [ratnums: rational numbers]
 complex:+  complex:*  complex:-  ...  [slonums: rectangular complex numbers]

...where int:<mumble> works on bignums and fixnums.

Those who really care about this sort of low-level arithmetic efficiency
can use these primitives.  Those who don't can use the generic ones and let
the compiler do some flow analysis to optimize some easy cases.

There is no issue of what is the `default'.  You either use + or fix:+,
etc.

Of course, there _is_ an issue of what is portable, since fix:<mumble> etc
are not part of the RnRS... but they could be (inefficiently) defined by
just: (define fix:+ +), etc. to at least maintain portability.

---

So are you now proposing that such a non-generic spectrum be added to the
R5RS so you can write portable programs explicitly using non-generic
arithmetic?

I seriously doubt anyone would strongly object to such a proposal.

Moreover, this, coupled with a portable extended syntax for type
declarations in lambda parameter lists (which I alluded to earlier but
which nobody has yet proposed) could give you a nice portable way to write
non-generic arithmetic programs.

And again Gerry Sussman and Bill Rozas at least would not object because
this already exists in their work-a-day Scheme implementation.