[Top][All Lists]

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

Re: [PATCH] Fix the R6RS exact-integer-sqrt and import into core guile

From: Mark H Weaver
Subject: Re: [PATCH] Fix the R6RS exact-integer-sqrt and import into core guile
Date: Sat, 09 Apr 2011 13:46:29 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

address@hidden (Ludovic Courtès) writes:
> OK.  I was thinking that I’d use C when dealing with fixnums or floats,
> and let Guile manage bignums and similar—in which case writing C doesn’t
> seem to help much.
> Do you think there are use cases for using this interface from C?

It is a fair question.  You could ask the same question about the C
interfaces for _all_ of Guile's numerical operators.  Why would anyone
want to use scm_sqrt or scm_sum or scm_less_p from C?

My answer is: in a C program that already uses Guile, they are useful
when you want to do arithmetic from C, but with the full numerical tower
of Scheme.  Most likely, you might want to be robust against integer
overflow, but you might also want to work with exact rationals.

Put another way: these functions are useful for the same reasons that
that GMP is useful for more than just writing interpreters.  Yes, some
people want to write the bulk of their code in C, even when they are
using such features.

I realize that many of us here (including me) will react by saying "But
that's madness!  Why not use Scheme in that case?"  There might be some
justifiable reasons, maybe because they care a lot about efficiency, but
they have a few areas where they're willing to pay the price for robust

Sometimes there's no good reason to use C, but it's simply due to a
developer's personal preference.  Maybe they don't have much experience
writing Scheme and are much more comfortable in C.  Maybe they already
had this big pile of C code before they learned to love Scheme.  Maybe
they're part of a larger team, most of whom either don't know Scheme or
are unwilling to use Scheme for the main project, but they want to add
user extensibility and chose Guile.  Since they already have libguile,
they might as well use its arithmetic functions in a few places to
improve robustness against overflows.

We cannot force people to use Scheme.  If we wish for libguile to be
attractive for use by projects primarily written in C, we ought to
extinguish this unfortunate recent tendency to say "people ought to be
writing Scheme not C", and we ought to stop using that as an excuse to
block improvements to the C interface.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]