diff options
author | Andy Wingo <wingo@pobox.com> | 2020-04-12 22:17:22 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2020-04-12 22:17:22 +0200 |
commit | cae74359decc1a9d28c7892c7344512178eeac2e (patch) | |
tree | 72984b9ae43c5aa79ad285caedbda6f83091cdb2 /libguile/deprecated.c | |
parent | 24a34074ef8fd91c111ed9987375f25925f69e26 (diff) | |
download | guile-cae74359decc1a9d28c7892c7344512178eeac2e.tar.gz |
Replace bit-count with bitvector-count
The old name was wonky and had bad argument order.
* NEWS: Add entry.
* doc/ref/api-data.texi (Bit Vectors): Update.
* libguile/bitvectors.h:
* libguile/bitvectors.c (VALIDATE_BITVECTOR): New helper.
(scm_bitvector_count): New function.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_bit_count): Deprecate.
* module/ice-9/sandbox.scm (bitvector-bindings): Replace bit-count with
bitvector-count.
* module/srfi/srfi-60.scm: No need to #:replace bit-count.
* module/system/vm/frame.scm (available-bindings): Use bitvector-count.
* test-suite/tests/bitvectors.test ("bitvector-count"): Add test.
Diffstat (limited to 'libguile/deprecated.c')
-rw-r--r-- | libguile/deprecated.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libguile/deprecated.c b/libguile/deprecated.c index 60459c603..e39d11e9d 100644 --- a/libguile/deprecated.c +++ b/libguile/deprecated.c @@ -27,9 +27,11 @@ #define SCM_BUILDING_DEPRECATED_CODE +#include "boolean.h" #include "bitvectors.h" #include "deprecation.h" #include "gc.h" +#include "gsubr.h" #include "strings.h" #include "deprecated.h" @@ -85,6 +87,43 @@ scm_find_executable (const char *name) +SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0, + (SCM b, SCM bitvector), + "Return the number of occurrences of the boolean @var{b} in\n" + "@var{bitvector}.") +#define FUNC_NAME s_scm_bit_count +{ + int bit = scm_to_bool (b); + size_t count = 0, len; + + scm_c_issue_deprecation_warning + ("bit-count is deprecated. Use bitvector-count, or a loop over array-ref " + "if array support is needed."); + + if (scm_is_true (scm_bitvector_p (bitvector))) + { + len = scm_to_size_t (scm_bitvector_length (bitvector)); + count = scm_to_size_t (scm_bitvector_count (bitvector)); + } + else + { + scm_t_array_handle handle; + size_t off; + ssize_t inc; + + scm_bitvector_elements (bitvector, &handle, &off, &len, &inc); + + for (size_t i = 0; i < len; i++) + if (scm_is_true (scm_array_handle_ref (&handle, i*inc))) + count++; + + scm_array_handle_release (&handle); + } + + return scm_from_size_t (bit ? count : len-count); +} +#undef FUNC_NAME + SCM scm_istr2bve (SCM str) { |