* tags.h, deprecated.h (SCM_EQ_P): Deprecated by moving it into
[bpt/guile.git] / libguile / unif.c
index 5e0a801..3abc8c7 100644 (file)
@@ -1,46 +1,20 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- * As a special exception, the Free Software Foundation gives permission
- * for additional uses of the text contained in its release of GUILE.
- *
- * The exception is that, if you link the GUILE library with other files
- * to produce an executable, this does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * Your use of that executable is in no way restricted on account of
- * linking the GUILE library code into it.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This exception does not however invalidate any other reasons why
- * the executable file might be covered by the GNU General Public License.
- *
- * This exception applies only to the code released by the
- * Free Software Foundation under the name GUILE.  If you copy
- * code from other Free Software Foundation releases into a copy of
- * GUILE, as the General Public License permits, the exception does
- * not apply to the code that you add in this way.  To avoid misleading
- * anyone as to the status of such modified files, you must delete
- * this exception notice from them.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * If you write modifications of your own for GUILE, it is your choice
- * whether to permit this exception to apply to your modifications.
- * If you do not wish that, delete this exception notice.  */
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
 
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 
 /*
   This file has code for arrays in lots of variants (double, integer,
 */
 \f
 
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+
 \f
 /* The set of uniform scm_vector types is:
  *  Vector of:          Called:
@@ -89,7 +71,8 @@
  * long long           llvect
  */
 
-scm_bits_t scm_tc16_array;
+scm_t_bits scm_tc16_array;
+static SCM exactly_one_third;
 
 /* return the size of an element in a uniform array or 0 if type not
    found.  */
@@ -114,7 +97,7 @@ scm_uniform_element_size (SCM obj)
       result = sizeof (short);
       break;
 
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       result = sizeof (long long);
       break;
@@ -144,7 +127,7 @@ scm_uniform_element_size (SCM obj)
 static int
 singp (SCM obj)
 {
-  if (!SCM_SLOPPY_REALP (obj))
+  if (!SCM_REALP (obj))
     return 0;
   else
     {
@@ -154,47 +137,47 @@ singp (SCM obj)
     }
 }
 
+static SCM
+make_uve (long type, long k, size_t size)
+#define FUNC_NAME "scm_make_uve"
+{
+  SCM_ASSERT_RANGE (1, scm_long2num (k), k <= SCM_UVECTOR_MAX_LENGTH);
+
+  return scm_cell (SCM_MAKE_UVECTOR_TAG (k, type),
+                  (scm_t_bits) scm_gc_malloc (k * size, "vector"));
+}
+#undef FUNC_NAME
+
 SCM 
 scm_make_uve (long k, SCM prot)
 #define FUNC_NAME "scm_make_uve"
 {
-  SCM v;
-  long i, type;
-
-  if (SCM_EQ_P (prot, SCM_BOOL_T))
+  if (scm_is_eq (prot, SCM_BOOL_T))
     {
-      SCM_NEWCELL (v);
       if (k > 0)
        {
-         SCM_ASSERT_RANGE (1, scm_long2num (k), k <= SCM_BITVECTOR_MAX_LENGTH);
+         long i;
+         SCM_ASSERT_RANGE (1,
+                           scm_long2num (k), k <= SCM_BITVECTOR_MAX_LENGTH);
          i = sizeof (long) * ((k + SCM_LONG_BIT - 1) / SCM_LONG_BIT);
-         SCM_SET_BITVECTOR_BASE (v, (char *) scm_must_malloc (i, "vector"));
-         SCM_SET_BITVECTOR_LENGTH (v, k);
+         return scm_cell (SCM_MAKE_BITVECTOR_TAG (k), 
+                          (scm_t_bits) scm_gc_malloc (i, "vector"));
        }
       else
-       {
-         SCM_SET_BITVECTOR_BASE (v, 0);
-         SCM_SET_BITVECTOR_LENGTH (v, 0);
-       }
-      return v;
+       return scm_cell (SCM_MAKE_BITVECTOR_TAG (0), 0);
     }
   else if (SCM_CHARP (prot) && (SCM_CHAR (prot) == '\0'))
-    {
-      i = sizeof (char) * k;
-      type = scm_tc7_byvect;
-    }
+    return make_uve (scm_tc7_byvect, k, sizeof (char));
   else if (SCM_CHARP (prot))
+    return scm_allocate_string (sizeof (char) * k);
+  else if (SCM_I_INUMP (prot))
+    return make_uve (SCM_I_INUM (prot) > 0 ? scm_tc7_uvect : scm_tc7_ivect,
+                    k,
+                    sizeof (long));
+  else if (SCM_FRACTIONP (prot))
     {
-      i = sizeof (char) * k;
-      return scm_allocate_string (i);
-    }
-  else if (SCM_INUMP (prot))
-    {
-      i = sizeof (long) * k;
-      if (SCM_INUM (prot) > 0)
-       type = scm_tc7_uvect;
-      else
-       type = scm_tc7_ivect;
+      if (scm_num_eq_p (exactly_one_third, prot))
+        goto dvect;
     }
   else if (SCM_SYMBOLP (prot) && (1 == SCM_SYMBOL_LENGTH (prot)))
     {
@@ -202,54 +185,27 @@ scm_make_uve (long k, SCM prot)
 
       s = SCM_SYMBOL_CHARS (prot)[0];
       if (s == 's')
-       {
-         i = sizeof (short) * k;
-         type = scm_tc7_svect;
-       }
-#ifdef HAVE_LONG_LONGS
+       return make_uve (scm_tc7_svect, k, sizeof (short));
+#if SCM_SIZEOF_LONG_LONG != 0
       else if (s == 'l')
-       {
-         i = sizeof (long long) * k;
-         type = scm_tc7_llvect;
-       }
+       return make_uve (scm_tc7_llvect, k, sizeof (long long));
 #endif
       else
-       {
-         return scm_c_make_vector (k, SCM_UNDEFINED);
-       }
+       return scm_c_make_vector (k, SCM_UNDEFINED);
     }
   else if (!SCM_INEXACTP (prot))
     /* Huge non-unif vectors are NOT supported. */
     /* no special scm_vector */
     return scm_c_make_vector (k, SCM_UNDEFINED);
   else if (singp (prot))
-    {
-      i = sizeof (float) * k;
-      type = scm_tc7_fvect;
-    }
+    return make_uve (scm_tc7_fvect, k, sizeof (float));
   else if (SCM_COMPLEXP (prot))
-    {
-      i = 2 * sizeof (double) * k;
-      type = scm_tc7_cvect;
-    }
-  else
-    {
-      i = sizeof (double) * k;
-      type = scm_tc7_dvect;
-    }
-
-  SCM_ASSERT_RANGE (1, scm_long2num (k), k <= SCM_UVECTOR_MAX_LENGTH);
-
-  SCM_NEWCELL (v);
-  SCM_DEFER_INTS;
-  SCM_SET_UVECTOR_BASE (v, (char *) scm_must_malloc (i ? i : 1, "vector"));
-  SCM_SET_UVECTOR_LENGTH (v, k, type);
-  SCM_ALLOW_INTS;
-  return v;
+    return make_uve (scm_tc7_cvect, k, 2 * sizeof (double));
+ dvect:
+  return make_uve (scm_tc7_dvect, k, sizeof (double));
 }
 #undef FUNC_NAME
 
-
 SCM_DEFINE (scm_uniform_vector_length, "uniform-vector-length", 1, 0, 0, 
            (SCM v),
            "Return the number of elements in @var{uve}.")
@@ -262,11 +218,11 @@ SCM_DEFINE (scm_uniform_vector_length, "uniform-vector-length", 1, 0, 0,
     badarg1:SCM_WRONG_TYPE_ARG (1, v);
     case scm_tc7_vector:
     case scm_tc7_wvect:
-      return SCM_MAKINUM (SCM_VECTOR_LENGTH (v));
+      return scm_from_size_t (SCM_VECTOR_LENGTH (v));
     case scm_tc7_string:
-      return SCM_MAKINUM (SCM_STRING_LENGTH (v));
+      return scm_from_size_t (SCM_STRING_LENGTH (v));
     case scm_tc7_bvect:
-      return SCM_MAKINUM (SCM_BITVECTOR_LENGTH (v));
+      return scm_from_size_t (SCM_BITVECTOR_LENGTH (v));
     case scm_tc7_byvect:
     case scm_tc7_uvect:
     case scm_tc7_ivect:
@@ -274,10 +230,10 @@ SCM_DEFINE (scm_uniform_vector_length, "uniform-vector-length", 1, 0, 0,
     case scm_tc7_dvect:
     case scm_tc7_cvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
-      return SCM_MAKINUM (SCM_UVECTOR_LENGTH (v));
+      return scm_from_size_t (SCM_UVECTOR_LENGTH (v));
     }
 }
 #undef FUNC_NAME
@@ -307,7 +263,7 @@ SCM_DEFINE (scm_array_p, "array?", 1, 1, 0,
       v = SCM_ARRAY_V (v);
      }
   if (nprot)
-    return SCM_BOOL(nprot);
+    return scm_from_bool(nprot);
   else
     {
       int protp = 0;
@@ -315,40 +271,52 @@ SCM_DEFINE (scm_array_p, "array?", 1, 1, 0,
       switch (SCM_TYP7 (v))
        {
        case scm_tc7_bvect:
-         protp = (SCM_EQ_P (prot, SCM_BOOL_T));
+         protp = (scm_is_eq (prot, SCM_BOOL_T));
+          break;
        case scm_tc7_string:
          protp = SCM_CHARP(prot) && (SCM_CHAR (prot) != '\0');
+          break;
        case scm_tc7_byvect:
-         protp = SCM_EQ_P (prot, SCM_MAKE_CHAR ('\0'));
+         protp = scm_is_eq (prot, SCM_MAKE_CHAR ('\0'));
+          break;
        case scm_tc7_uvect:
-         protp = SCM_INUMP(prot) && SCM_INUM(prot)>0;
+         protp = SCM_I_INUMP(prot) && SCM_I_INUM(prot)>0;
+          break;
        case scm_tc7_ivect:
-         protp = SCM_INUMP(prot) && SCM_INUM(prot)<=0;
-          
+         protp = SCM_I_INUMP(prot) && SCM_I_INUM(prot)<=0;
+          break;
        case scm_tc7_svect:
          protp = SCM_SYMBOLP (prot)
            && (1 == SCM_SYMBOL_LENGTH (prot))
            && ('s' == SCM_SYMBOL_CHARS (prot)[0]);
-#ifdef HAVE_LONG_LONGS
+          break;
+#if SCM_SIZEOF_LONG_LONG != 0
        case scm_tc7_llvect:
          protp = SCM_SYMBOLP (prot)
            && (1 == SCM_SYMBOL_LENGTH (prot))
-           && ('s' == SCM_SYMBOL_CHARS (prot)[0]);
+           && ('l' == SCM_SYMBOL_CHARS (prot)[0]);
+          break;
 #endif
        case scm_tc7_fvect:
          protp = singp (prot);
+          break;
        case scm_tc7_dvect:
-         protp = SCM_REALP(prot);
+         protp = ((SCM_REALP(prot) && ! singp (prot))
+                   || (SCM_FRACTIONP (prot)
+                       && scm_num_eq_p (exactly_one_third, prot)));
+          break;
        case scm_tc7_cvect:
          protp = SCM_COMPLEXP(prot);
+          break;
        case scm_tc7_vector:
        case scm_tc7_wvect:
          protp = SCM_NULLP(prot);
+          break;
        default:
          /* no default */
          ;
        }
-      return SCM_BOOL(protp);
+      return scm_from_bool(protp);
     }
 }
 #undef FUNC_NAME
@@ -375,14 +343,14 @@ SCM_DEFINE (scm_array_rank, "array-rank", 1, 0, 0,
     case scm_tc7_fvect:
     case scm_tc7_cvect:
     case scm_tc7_dvect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
     case scm_tc7_svect:
-      return SCM_MAKINUM (1L);
+      return scm_from_int (1);
     case scm_tc7_smob:
       if (SCM_ARRAYP (ra))
-       return SCM_MAKINUM (SCM_ARRAY_NDIM (ra));
+       return scm_from_size_t (SCM_ARRAY_NDIM (ra));
       return SCM_INUM0;
     }
 }
@@ -400,7 +368,7 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
 {
   SCM res = SCM_EOL;
   size_t k;
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
   if (SCM_IMP (ra))
     return SCM_BOOL_F;
   switch (SCM_TYP7 (ra))
@@ -418,7 +386,7 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
     case scm_tc7_cvect:
     case scm_tc7_dvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
       return scm_cons (scm_uniform_vector_length (ra), SCM_EOL);
@@ -429,10 +397,10 @@ SCM_DEFINE (scm_array_dimensions, "array-dimensions", 1, 0, 0,
       s = SCM_ARRAY_DIMS (ra);
       while (k--)
        res = scm_cons (s[k].lbnd
-                       ? scm_cons2 (SCM_MAKINUM (s[k].lbnd),
-                                    SCM_MAKINUM (s[k].ubnd),
+                       ? scm_cons2 (scm_from_long (s[k].lbnd),
+                                    scm_from_long (s[k].ubnd),
                                     SCM_EOL)
-                       : SCM_MAKINUM (1 + s[k].ubnd),
+                       : scm_from_long (1 + s[k].ubnd),
                        res);
       return res;
     }
@@ -457,7 +425,7 @@ SCM_DEFINE (scm_shared_array_offset, "shared-array-offset", 1, 0, 0,
 #define FUNC_NAME s_scm_shared_array_offset
 {
   SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME);
-  return SCM_MAKINUM (SCM_ARRAY_BASE (ra));
+  return scm_from_int (SCM_ARRAY_BASE (ra));
 }
 #undef FUNC_NAME
 
@@ -469,12 +437,12 @@ SCM_DEFINE (scm_shared_array_increments, "shared-array-increments", 1, 0, 0,
 {
   SCM res = SCM_EOL;
   size_t k;
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
   SCM_ASSERT (SCM_ARRAYP (ra), ra, SCM_ARG1, FUNC_NAME);
   k = SCM_ARRAY_NDIM (ra);
   s = SCM_ARRAY_DIMS (ra);
   while (k--)
-    res = scm_cons (SCM_MAKINUM (s[k].inc), res);
+    res = scm_cons (scm_from_long (s[k].inc), res);
   return res;
 }
 #undef FUNC_NAME
@@ -491,20 +459,20 @@ scm_aind (SCM ra, SCM args, const char *what)
   register long j;
   register unsigned long pos = SCM_ARRAY_BASE (ra);
   register unsigned long k = SCM_ARRAY_NDIM (ra);
-  scm_array_dim_t *s = SCM_ARRAY_DIMS (ra);
-  if (SCM_INUMP (args))
+  scm_t_array_dim *s = SCM_ARRAY_DIMS (ra);
+  if (scm_is_integer (args))
     {
       if (k != 1)
        scm_error_num_args_subr (what);
-      return pos + (SCM_INUM (args) - s->lbnd) * (s->inc);
+      return pos + (scm_to_long (args) - s->lbnd) * (s->inc);
     }
-  while (k && !SCM_NULLP (args))
+  while (k && SCM_CONSP (args))
     {
       ind = SCM_CAR (args);
       args = SCM_CDR (args);
-      if (!SCM_INUMP (ind))
+      if (!scm_is_integer (ind))
        scm_misc_error (what, s_bad_ind, SCM_EOL);
-      j = SCM_INUM (ind);
+      j = scm_to_long (ind);
       if (j < s->lbnd || j > s->ubnd)
        scm_out_of_range (what, ind);
       pos += (j - s->lbnd) * (s->inc);
@@ -523,12 +491,11 @@ SCM
 scm_make_ra (int ndim)
 {
   SCM ra;
-  SCM_NEWCELL (ra);
   SCM_DEFER_INTS;
-  SCM_NEWSMOB(ra, ((scm_bits_t) ndim << 17) + scm_tc16_array,
-              scm_must_malloc ((sizeof (scm_array_t) +
-                               ndim * sizeof (scm_array_dim_t)),
-                              "array"));
+  SCM_NEWSMOB(ra, ((scm_t_bits) ndim << 17) + scm_tc16_array,
+              scm_gc_malloc ((sizeof (scm_t_array) +
+                             ndim * sizeof (scm_t_array_dim)),
+                            "array"));
   SCM_ARRAY_V (ra) = scm_nullvect;
   SCM_ALLOW_INTS;
   return ra;
@@ -541,7 +508,7 @@ static char s_bad_spec[] = "Bad scm_array dimension";
 SCM 
 scm_shap2ra (SCM args, const char *what)
 {
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
   SCM ra, spec, sp;
   int ndim = scm_ilength (args);
   if (ndim < 0)
@@ -553,25 +520,25 @@ scm_shap2ra (SCM args, const char *what)
   for (; !SCM_NULLP (args); s++, args = SCM_CDR (args))
     {
       spec = SCM_CAR (args);
-      if (SCM_INUMP (spec))
+      if (scm_is_integer (spec))
        {
-         if (SCM_INUM (spec) < 0)
+         if (scm_to_long (spec) < 0)
            scm_misc_error (what, s_bad_spec, SCM_EOL);
          s->lbnd = 0;
-         s->ubnd = SCM_INUM (spec) - 1;
+         s->ubnd = scm_to_long (spec) - 1;
          s->inc = 1;
        }
       else
        {
-         if (!SCM_CONSP (spec) || !SCM_INUMP (SCM_CAR (spec)))
+         if (!SCM_CONSP (spec) || !scm_is_integer (SCM_CAR (spec)))
            scm_misc_error (what, s_bad_spec, SCM_EOL);
-         s->lbnd = SCM_INUM (SCM_CAR (spec));
+         s->lbnd = scm_to_long (SCM_CAR (spec));
          sp = SCM_CDR (spec);
          if (!SCM_CONSP (sp) 
-             || !SCM_INUMP (SCM_CAR (sp))
+             || !scm_is_integer (SCM_CAR (sp))
              || !SCM_NULLP (SCM_CDR (sp)))
            scm_misc_error (what, s_bad_spec, SCM_EOL);
-         s->ubnd = SCM_INUM (SCM_CAR (sp));
+         s->ubnd = scm_to_long (SCM_CAR (sp));
          s->inc = 1;
        }
     }
@@ -580,7 +547,7 @@ scm_shap2ra (SCM args, const char *what)
 
 SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1, 0,
            (SCM dims, SCM prot, SCM fill),
-           "@deffnx primitive make-uniform-vector length prototype [fill]\n"
+           "@deffnx {Scheme Procedure} make-uniform-vector length prototype [fill]\n"
            "Create and return a uniform array or vector of type\n"
            "corresponding to @var{prototype} with dimensions @var{dims} or\n"
            "length @var{length}.  If @var{fill} is supplied, it's used to\n"
@@ -589,16 +556,16 @@ SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1,
 {
   size_t k;
   unsigned long rlen = 1;
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
   SCM ra;
   
-  if (SCM_INUMP (dims))
+  if (scm_is_integer (dims))
     {
-      SCM answer = scm_make_uve (SCM_INUM (dims), prot);
+      SCM answer = scm_make_uve (scm_to_long (dims), prot);
       if (!SCM_UNBNDP (fill))
        scm_array_fill_x (answer, fill);
       else if (SCM_SYMBOLP (prot))
-       scm_array_fill_x (answer, SCM_MAKINUM (0));
+       scm_array_fill_x (answer, scm_from_int (0));
       else
        scm_array_fill_x (answer, prot);
       return answer;
@@ -623,7 +590,7 @@ SCM_DEFINE (scm_dimensions_to_uniform_array, "dimensions->uniform-array", 2, 1,
   if (!SCM_UNBNDP (fill))
     scm_array_fill_x (ra, fill);
   else if (SCM_SYMBOLP (prot))
-    scm_array_fill_x (ra, SCM_MAKINUM (0));
+    scm_array_fill_x (ra, scm_from_int (0));
   else
     scm_array_fill_x (ra, prot);
 
@@ -681,11 +648,11 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
   SCM imap;
   size_t k, i;
   long old_min, new_min, old_max, new_max;
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
 
   SCM_VALIDATE_REST_ARGUMENT (dims);
-  SCM_VALIDATE_ARRAY (1,oldra);
-  SCM_VALIDATE_PROC (2,mapfunc);
+  SCM_VALIDATE_ARRAY (1, oldra);
+  SCM_VALIDATE_PROC (2, mapfunc);
   ra = scm_shap2ra (dims, FUNC_NAME);
   if (SCM_ARRAYP (oldra))
     {
@@ -705,13 +672,13 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
     {
       SCM_ARRAY_V (ra) = oldra;
       old_min = 0;
-      old_max = SCM_INUM (scm_uniform_vector_length (oldra)) - 1;
+      old_max = scm_to_long (scm_uniform_vector_length (oldra)) - 1;
     }
   inds = SCM_EOL;
   s = SCM_ARRAY_DIMS (ra);
   for (k = 0; k < SCM_ARRAY_NDIM (ra); k++)
     {
-      inds = scm_cons (SCM_MAKINUM (s[k].lbnd), inds);
+      inds = scm_cons (scm_from_long (s[k].lbnd), inds);
       if (s[k].ubnd < s[k].lbnd)
        {
          if (1 == SCM_ARRAY_NDIM (ra))
@@ -721,19 +688,18 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
          return ra;
        }
     }
-  imap = scm_apply (mapfunc, scm_reverse (inds), SCM_EOL);
+  imap = scm_apply_0 (mapfunc, scm_reverse (inds));
   if (SCM_ARRAYP (oldra))
       i = (size_t) scm_aind (oldra, imap, FUNC_NAME);
   else
     {
-      if (SCM_NINUMP (imap))
-
+      if (!scm_is_integer (imap))
        {
-         if (scm_ilength (imap) != 1 || !SCM_INUMP (SCM_CAR (imap)))
+         if (scm_ilength (imap) != 1 || !scm_is_integer (SCM_CAR (imap)))
            SCM_MISC_ERROR (s_bad_ind, SCM_EOL);
          imap = SCM_CAR (imap);
        }
-      i = SCM_INUM (imap);
+      i = scm_to_size_t (imap);
     }
   SCM_ARRAY_BASE (ra) = new_min = new_max = i;
   indptr = inds;
@@ -742,20 +708,20 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
     {
       if (s[k].ubnd > s[k].lbnd)
        {
-         SCM_SETCAR (indptr, SCM_MAKINUM (SCM_INUM (SCM_CAR (indptr)) + 1));
-         imap = scm_apply (mapfunc, scm_reverse (inds), SCM_EOL);
+         SCM_SETCAR (indptr, scm_sum (SCM_CAR (indptr), scm_from_int (1)));
+         imap = scm_apply_0 (mapfunc, scm_reverse (inds));
          if (SCM_ARRAYP (oldra))
 
              s[k].inc = scm_aind (oldra, imap, FUNC_NAME) - i;
          else
            {
-             if (SCM_NINUMP (imap))
+             if (!scm_is_integer (imap))
                {
-                 if (scm_ilength (imap) != 1 || !SCM_INUMP (SCM_CAR (imap)))
+                 if (scm_ilength (imap) != 1 || !scm_is_integer (SCM_CAR (imap)))
                    SCM_MISC_ERROR (s_bad_ind, SCM_EOL);
                  imap = SCM_CAR (imap);
                }
-             s[k].inc = (long) SCM_INUM (imap) - i;
+             s[k].inc = scm_to_long (imap) - i;
            }
          i += s[k].inc;
          if (s[k].inc > 0)
@@ -772,7 +738,7 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
   if (1 == SCM_ARRAY_NDIM (ra) && 0 == SCM_ARRAY_BASE (ra))
     {
       SCM v = SCM_ARRAY_V (ra);
-      unsigned long int length = SCM_INUM (scm_uniform_vector_length (v));
+      unsigned long int length = scm_to_ulong (scm_uniform_vector_length (v));
       if (1 == s->inc && 0 == s->lbnd && length == 1 + s->ubnd)
        return v;
       if (s->ubnd < s->lbnd)
@@ -808,8 +774,9 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
            "@end lisp")
 #define FUNC_NAME s_scm_transpose_array
 {
-  SCM res, vargs, *ve = &vargs;
-  scm_array_dim_t *s, *r;
+  SCM res, vargs;
+  SCM const *ve = &vargs;
+  scm_t_array_dim *s, *r;
   int ndim, i, k;
 
   SCM_VALIDATE_REST_ARGUMENT (args);
@@ -827,14 +794,13 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
     case scm_tc7_dvect:
     case scm_tc7_cvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
       if (SCM_NULLP (args) || !SCM_NULLP (SCM_CDR (args)))
        SCM_WRONG_NUM_ARGS ();
-      SCM_VALIDATE_INUM (SCM_ARG2, SCM_CAR (args));
-      SCM_ASSERT_RANGE (SCM_ARG2, SCM_CAR (args), 
-                       SCM_EQ_P (SCM_INUM0, SCM_CAR (args)));
+      SCM_VALIDATE_INT_COPY (SCM_ARG2, SCM_CAR (args), i);
+      SCM_ASSERT_RANGE (SCM_ARG2, SCM_CAR (args), i == 0);
       return ra;
     case scm_tc7_smob:
       SCM_ASRTGO (SCM_ARRAYP (ra), badarg);
@@ -845,11 +811,7 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
       ndim = 0;
       for (k = 0; k < SCM_ARRAY_NDIM (ra); k++)
        {
-         SCM_ASSERT (SCM_INUMP (ve[k]), ve[k], (SCM_ARG2 + k),
-                     FUNC_NAME);
-         i = SCM_INUM (ve[k]);
-         if (i < 0 || i >= SCM_ARRAY_NDIM (ra))
-           scm_out_of_range (FUNC_NAME, ve[k]);
+         i = scm_to_signed_integer (ve[k], 0, SCM_ARRAY_NDIM(ra));
          if (ndim < i)
            ndim = i;
        }
@@ -864,7 +826,7 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
        }
       for (k = SCM_ARRAY_NDIM (ra); k--;)
        {
-         i = SCM_INUM (ve[k]);
+         i = scm_to_int (ve[k]);
          s = &(SCM_ARRAY_DIMS (ra)[k]);
          r = &(SCM_ARRAY_DIMS (res)[i]);
          if (r->ubnd < r->lbnd)
@@ -918,12 +880,12 @@ SCM_DEFINE (scm_enclose_array, "enclose-array", 1, 0, 1,
 #define FUNC_NAME s_scm_enclose_array
 {
   SCM axv, res, ra_inr;
-  scm_array_dim_t vdim, *s = &vdim;
+  scm_t_array_dim vdim, *s = &vdim;
   int ndim, j, k, ninr, noutr;
 
   SCM_VALIDATE_REST_ARGUMENT (axes);
   if (SCM_NULLP (axes))
-      axes = scm_cons ((SCM_ARRAYP (ra) ? SCM_MAKINUM (SCM_ARRAY_NDIM (ra) - 1) : SCM_INUM0), SCM_EOL);
+      axes = scm_cons ((SCM_ARRAYP (ra) ? scm_from_size_t (SCM_ARRAY_NDIM (ra) - 1) : SCM_INUM0), SCM_EOL);
   ninr = scm_ilength (axes);
   if (ninr < 0)
     SCM_WRONG_NUM_ARGS ();
@@ -944,11 +906,11 @@ SCM_DEFINE (scm_enclose_array, "enclose-array", 1, 0, 1,
     case scm_tc7_vector:
     case scm_tc7_wvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
       s->lbnd = 0;
-      s->ubnd = SCM_INUM (scm_uniform_vector_length (ra)) - 1;
+      s->ubnd = scm_to_long (scm_uniform_vector_length (ra)) - 1;
       s->inc = 1;
       SCM_ARRAY_V (ra_inr) = ra;
       SCM_ARRAY_BASE (ra_inr) = 0;
@@ -965,15 +927,15 @@ SCM_DEFINE (scm_enclose_array, "enclose-array", 1, 0, 1,
   noutr = ndim - ninr;
   if (noutr < 0)
     SCM_WRONG_NUM_ARGS ();
-  axv = scm_make_string (SCM_MAKINUM (ndim), SCM_MAKE_CHAR (0));
+  axv = scm_make_string (scm_from_int (ndim), SCM_MAKE_CHAR (0));
   res = scm_make_ra (noutr);
   SCM_ARRAY_BASE (res) = SCM_ARRAY_BASE (ra_inr);
   SCM_ARRAY_V (res) = ra_inr;
   for (k = 0; k < ninr; k++, axes = SCM_CDR (axes))
     {
-      if (!SCM_INUMP (SCM_CAR (axes)))
+      if (!scm_is_integer (SCM_CAR (axes)))
        SCM_MISC_ERROR ("bad axis", SCM_EOL);
-      j = SCM_INUM (SCM_CAR (axes));
+      j = scm_to_int (SCM_CAR (axes));
       SCM_ARRAY_DIMS (ra_inr)[k].lbnd = s[j].lbnd;
       SCM_ARRAY_DIMS (ra_inr)[k].ubnd = s[j].ubnd;
       SCM_ARRAY_DIMS (ra_inr)[k].inc = s[j].inc;
@@ -1005,7 +967,7 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
   long pos = 0;
   register size_t k;
   register long j;
-  scm_array_dim_t *s;
+  scm_t_array_dim *s;
 
   SCM_VALIDATE_REST_ARGUMENT (args);
   SCM_ASRTGO (SCM_NIMP (v), badarg1);
@@ -1014,8 +976,7 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
     {
       ind = SCM_CAR (args);
       args = SCM_CDR (args);
-      SCM_ASSERT (SCM_INUMP (ind), ind, SCM_ARG2, FUNC_NAME);
-      pos = SCM_INUM (ind);
+      pos = scm_to_long (ind);
     }
 tail:
   switch SCM_TYP7 (v)
@@ -1035,7 +996,7 @@ tail:
       else
        while (!0)
          {
-           j = SCM_INUM (ind);
+           j = scm_to_long (ind);
            if (!(j >= (s->lbnd) && j <= (s->ubnd)))
              {
                SCM_ASRTGO (--k == scm_ilength (args), wna);
@@ -1047,7 +1008,7 @@ tail:
            ind = SCM_CAR (args);
            args = SCM_CDR (args);
            s++;
-           if (!SCM_INUMP (ind))
+           if (!scm_is_integer (ind))
              SCM_MISC_ERROR (s_bad_ind, SCM_EOL);
          }
       SCM_ASRTGO (0 == k, wna);
@@ -1062,15 +1023,15 @@ tail:
     case scm_tc7_dvect:
     case scm_tc7_cvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
     case scm_tc7_vector:
     case scm_tc7_wvect:
       {
-       unsigned long int length = SCM_INUM (scm_uniform_vector_length (v));
-       SCM_ASRTGO (SCM_NULLP (args) && SCM_INUMP (ind), wna);
-       return SCM_BOOL(pos >= 0 && pos < length);
+       unsigned long length = scm_to_ulong (scm_uniform_vector_length (v));
+       SCM_ASRTGO (SCM_NULLP (args) && scm_is_integer (ind), wna);
+       return scm_from_bool(pos >= 0 && pos < length);
       }
     }
 }
@@ -1082,7 +1043,7 @@ SCM_REGISTER_PROC(s_array_ref, "array-ref", 1, 0, 1, scm_uniform_vector_ref);
 
 SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
            (SCM v, SCM args),
-           "@deffnx primitive array-ref v . args\n"
+           "@deffnx {Scheme Procedure} array-ref v . args\n"
            "Return the element at the @code{(index1, index2)} element in\n"
            "@var{array}.")
 #define FUNC_NAME s_scm_uniform_vector_ref
@@ -1104,16 +1065,15 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
       unsigned long int length;
       if (SCM_NIMP (args))
        {
-         SCM_ASSERT (SCM_CONSP (args) && SCM_INUMP (SCM_CAR (args)), args, SCM_ARG2, FUNC_NAME);
-         pos = SCM_INUM (SCM_CAR (args));
+         SCM_ASSERT (SCM_CONSP (args), args, SCM_ARG2, FUNC_NAME);
+         pos = scm_to_long (SCM_CAR (args));
          SCM_ASRTGO (SCM_NULLP (SCM_CDR (args)), wna);
        }
       else
        {
-          SCM_VALIDATE_INUM (2,args);
-         pos = SCM_INUM (args);
+         pos = scm_to_long (args);
        }
-      length = SCM_INUM (scm_uniform_vector_length (v));
+      length = scm_to_ulong (scm_uniform_vector_length (v));
       SCM_ASRTGO (pos >= 0 && pos < length, outrng);
     }
   switch SCM_TYP7 (v)
@@ -1126,7 +1086,7 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
       /* not reached */
 
     outrng:
-      scm_out_of_range (FUNC_NAME, SCM_MAKINUM (pos));
+      scm_out_of_range (FUNC_NAME, scm_from_long (pos));
     wna:
       SCM_WRONG_NUM_ARGS ();
     case scm_tc7_smob:
@@ -1151,17 +1111,17 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
     case scm_tc7_string:
       return SCM_MAKE_CHAR (SCM_STRING_UCHARS (v)[pos]);
     case scm_tc7_byvect:
-      return SCM_MAKINUM (((char *) SCM_UVECTOR_BASE (v))[pos]);
+      return scm_from_char (((char *) SCM_UVECTOR_BASE (v))[pos]);
   case scm_tc7_uvect:
-    return scm_ulong2num (((unsigned long *) SCM_VELTS (v))[pos]);
+    return scm_from_ulong (((unsigned long *) SCM_VELTS (v))[pos]);
   case scm_tc7_ivect:
-    return scm_long2num (((signed long *) SCM_VELTS (v))[pos]);
+    return scm_from_long (((signed long *) SCM_VELTS (v))[pos]);
 
     case scm_tc7_svect:
-      return SCM_MAKINUM (((short *) SCM_CELL_WORD_1 (v))[pos]);
-#ifdef HAVE_LONG_LONGS
+      return scm_from_short (((short *) SCM_CELL_WORD_1 (v))[pos]);
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
-      return scm_long_long2num (((long long *) SCM_CELL_WORD_1 (v))[pos]);
+      return scm_from_long_long (((long long *) SCM_CELL_WORD_1 (v))[pos]);
 #endif
 
     case scm_tc7_fvect:
@@ -1190,40 +1150,40 @@ scm_cvref (SCM v, unsigned long pos, SCM last)
     default:
       SCM_WRONG_TYPE_ARG (SCM_ARG1, v);
     case scm_tc7_bvect:
-      if (SCM_BITVEC_REF(v,pos))
+      if (SCM_BITVEC_REF(v, pos))
        return SCM_BOOL_T;
       else
        return SCM_BOOL_F;
     case scm_tc7_string:
       return SCM_MAKE_CHAR (SCM_STRING_UCHARS (v)[pos]);
     case scm_tc7_byvect:
-      return SCM_MAKINUM (((char *) SCM_UVECTOR_BASE (v))[pos]);
+      return scm_from_char (((char *) SCM_UVECTOR_BASE (v))[pos]);
     case scm_tc7_uvect:
-      return scm_ulong2num(((unsigned long *) SCM_VELTS (v))[pos]);
+      return scm_from_ulong (((unsigned long *) SCM_VELTS (v))[pos]);
     case scm_tc7_ivect:
-      return scm_long2num(((signed long *) SCM_VELTS (v))[pos]);
+      return scm_from_long (((signed long *) SCM_VELTS (v))[pos]);
     case scm_tc7_svect:
-      return SCM_MAKINUM (((short *) SCM_CELL_WORD_1 (v))[pos]);
-#ifdef HAVE_LONG_LONGS
+      return scm_from_short (((short *) SCM_CELL_WORD_1 (v))[pos]);
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
-      return scm_long_long2num (((long long *) SCM_CELL_WORD_1 (v))[pos]);
+      return scm_from_long_long (((long long *) SCM_CELL_WORD_1 (v))[pos]);
 #endif
     case scm_tc7_fvect:
-      if (SCM_NIMP (last) && !SCM_EQ_P (last, scm_flo0) && SCM_SLOPPY_REALP (last))
+      if (SCM_REALP (last) && !scm_is_eq (last, scm_flo0))
        {
          SCM_REAL_VALUE (last) = ((float *) SCM_CELL_WORD_1 (v))[pos];
          return last;
        }
       return scm_make_real (((float *) SCM_CELL_WORD_1 (v))[pos]);
     case scm_tc7_dvect:
-      if (SCM_NIMP (last) && !SCM_EQ_P (last, scm_flo0) && SCM_SLOPPY_REALP (last))
+      if (SCM_REALP (last) && !scm_is_eq (last, scm_flo0))
        {
          SCM_REAL_VALUE (last) = ((double *) SCM_CELL_WORD_1 (v))[pos];
          return last;
        }
       return scm_make_real (((double *) SCM_CELL_WORD_1 (v))[pos]);
     case scm_tc7_cvect:
-      if (SCM_NIMP (last) && SCM_SLOPPY_COMPLEXP (last))
+      if (SCM_COMPLEXP (last))
        {
          SCM_COMPLEX_REAL (last) = ((double *) SCM_CELL_WORD_1 (v))[2 * pos];
          SCM_COMPLEX_IMAG (last) = ((double *) SCM_CELL_WORD_1 (v))[2 * pos + 1];
@@ -1260,14 +1220,13 @@ SCM_REGISTER_PROC(s_uniform_array_set1_x, "uniform-array-set1!", 3, 0, 0, scm_ar
    PROC is used (and it's called from C too).  */
 SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1, 
            (SCM v, SCM obj, SCM args),
-           "@deffnx primitive uniform-array-set1! v obj args\n"
-           "Sets the element at the @code{(index1, index2)} element in @var{array} to\n"
+           "@deffnx {Scheme Procedure} uniform-array-set1! v obj args\n"
+           "Set the element at the @code{(index1, index2)} element in @var{array} to\n"
            "@var{new-value}.  The value returned by array-set! is unspecified.")
 #define FUNC_NAME s_scm_array_set_x           
 {
   long pos = 0;
 
-  SCM_VALIDATE_REST_ARGUMENT (args);
   SCM_ASRTGO (SCM_NIMP (v), badarg1);
   if (SCM_ARRAYP (v))
     {
@@ -1277,18 +1236,16 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
   else
     {
       unsigned long int length;
-      if (SCM_NIMP (args))
+      if (SCM_CONSP (args))
        {
-         SCM_ASSERT (SCM_CONSP(args) && SCM_INUMP (SCM_CAR (args)), args,
-                SCM_ARG3, FUNC_NAME);
          SCM_ASRTGO (SCM_NULLP (SCM_CDR (args)), wna);
-         pos = SCM_INUM (SCM_CAR (args));
+         pos = scm_to_long (SCM_CAR (args));
        }
       else
        {
-          SCM_VALIDATE_INUM_COPY (3,args,pos);
+         pos = scm_to_long (args);
        }
-      length = SCM_INUM (scm_uniform_vector_length (v));
+      length = scm_to_ulong (scm_uniform_vector_length (v));
       SCM_ASRTGO (pos >= 0 && pos < length, outrng);
     }
   switch (SCM_TYP7 (v))
@@ -1297,16 +1254,16 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
       SCM_WRONG_TYPE_ARG (1, v);
       /* not reached */
     outrng:
-      scm_out_of_range (FUNC_NAME, SCM_MAKINUM (pos));
+      scm_out_of_range (FUNC_NAME, scm_from_long (pos));
     wna:
       SCM_WRONG_NUM_ARGS ();
     case scm_tc7_smob:         /* enclosed */
       goto badarg1;
     case scm_tc7_bvect:
-      if (SCM_FALSEP (obj))
-       SCM_BITVEC_CLR(v,pos);
-      else if (SCM_EQ_P (obj, SCM_BOOL_T))
-       SCM_BITVEC_SET(v,pos);
+      if (scm_is_false (obj))
+       SCM_BITVEC_CLR(v, pos);
+      else if (scm_is_eq (obj, SCM_BOOL_T))
+       SCM_BITVEC_SET(v, pos);
       else
        badobj:SCM_WRONG_TYPE_ARG (2, obj);
       break;
@@ -1316,9 +1273,8 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
       break;
     case scm_tc7_byvect:
       if (SCM_CHARP (obj))
-       obj = SCM_MAKINUM ((char) SCM_CHAR (obj));
-      SCM_ASRTGO (SCM_INUMP (obj), badobj);
-      ((char *) SCM_UVECTOR_BASE (v))[pos] = SCM_INUM (obj);
+       obj = scm_from_char ((char) SCM_CHAR (obj));
+      ((char *) SCM_UVECTOR_BASE (v))[pos] = scm_to_char (obj);
       break;
     case scm_tc7_uvect:
       ((unsigned long *) SCM_UVECTOR_BASE (v))[pos] 
@@ -1329,10 +1285,9 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
        = scm_num2long (obj, SCM_ARG2, FUNC_NAME);
       break;
     case scm_tc7_svect:
-      SCM_ASRTGO (SCM_INUMP (obj), badobj);
-      ((short *) SCM_UVECTOR_BASE (v))[pos] = SCM_INUM (obj);
+      ((short *) SCM_UVECTOR_BASE (v))[pos] = scm_to_short (obj);
       break;
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       ((long long *) SCM_UVECTOR_BASE (v))[pos]
        = scm_num2long_long (obj, SCM_ARG2, FUNC_NAME);
@@ -1358,7 +1313,7 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
       break;
     case scm_tc7_vector:
     case scm_tc7_wvect:
-      SCM_VELTS (v)[pos] = obj;
+      SCM_VECTOR_SET (v, pos, obj);
       break;
     }
   return SCM_UNSPECIFIED;
@@ -1371,7 +1326,6 @@ SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
                     wouldn't have contiguous elements.  */
 SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
            (SCM ra, SCM strict),
-           "@deffnx primitive array-contents array strict\n"
            "If @var{array} may be @dfn{unrolled} into a one dimensional shared array\n"
            "without changing their order (last subscript changing fastest), then\n"
            "@code{array-contents} returns that shared array, otherwise it returns\n"
@@ -1401,7 +1355,7 @@ SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
     case scm_tc7_dvect:
     case scm_tc7_cvect:
     case scm_tc7_svect:
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
 #endif
       return ra;
@@ -1427,7 +1381,7 @@ SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
 
        {
          SCM v = SCM_ARRAY_V (ra);
-         unsigned long int length = SCM_INUM (scm_uniform_vector_length (v));
+         unsigned long length = scm_to_ulong (scm_uniform_vector_length (v));
          if ((len == length) && 0 == SCM_ARRAY_BASE (ra) && SCM_ARRAY_DIMS (ra)->inc)
            return v;
        }
@@ -1472,7 +1426,7 @@ scm_ra2contig (SCM ra, int copy)
       SCM_ARRAY_DIMS (ret)[k].inc = inc;
       inc *= SCM_ARRAY_DIMS (ra)[k].ubnd - SCM_ARRAY_DIMS (ra)[k].lbnd + 1;
     }
-  SCM_ARRAY_V (ret) = scm_make_uve ((inc - 1), scm_array_prototype (ra));
+  SCM_ARRAY_V (ret) = scm_make_uve (inc, scm_array_prototype (ra));
   if (copy)
     scm_array_copy_x (ra, ret);
   return ret;
@@ -1482,11 +1436,11 @@ scm_ra2contig (SCM ra, int copy)
 
 SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
            (SCM ra, SCM port_or_fd, SCM start, SCM end),
-           "@deffnx primitive uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
-           "Attempts to read all elements of @var{ura}, in lexicographic order, as\n"
+           "@deffnx {Scheme Procedure} uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
+           "Attempt to read all elements of @var{ura}, in lexicographic order, as\n"
            "binary objects from @var{port-or-fdes}.\n"
-           "If an end of file is encountered during\n"
-           "uniform-array-read! the objects up to that point only are put into @var{ura}\n"
+           "If an end of file is encountered,\n"
+           "the objects up to that point are put into @var{ura}\n"
            "(starting at the beginning) and the remainder of the array is\n"
            "unchanged.\n\n"
            "The optional arguments @var{start} and @var{end} allow\n"
@@ -1508,10 +1462,12 @@ SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
   if (SCM_UNBNDP (port_or_fd))
     port_or_fd = scm_cur_inp;
   else
-    SCM_ASSERT (SCM_INUMP (port_or_fd)
+    SCM_ASSERT (scm_is_integer (port_or_fd)
                || (SCM_OPINPORTP (port_or_fd)),
                port_or_fd, SCM_ARG2, FUNC_NAME);
-  vlen = SCM_INUM (scm_uniform_vector_length (v));
+  vlen = (SCM_TYP7 (v) == scm_tc7_smob
+         ? 0
+         : scm_to_long (scm_uniform_vector_length (v)));
 
 loop:
   switch SCM_TYP7 (v)
@@ -1549,7 +1505,7 @@ loop:
       base = (char *) SCM_UVECTOR_BASE (v);
       sz = sizeof (short);
       break;
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       base = (char *) SCM_UVECTOR_BASE (v);
       sz = sizeof (long long);
@@ -1591,7 +1547,7 @@ loop:
 
   if (SCM_NIMP (port_or_fd))
     {
-      scm_port_t *pt = SCM_PTAB_ENTRY (port_or_fd);
+      scm_t_port *pt = SCM_PTAB_ENTRY (port_or_fd);
       int remaining = (cend - offset) * sz;
       char *dest = base + (cstart + offset) * sz;
 
@@ -1630,7 +1586,7 @@ loop:
     }
   else /* file descriptor.  */
     {
-      SCM_SYSCALL (ans = read (SCM_INUM (port_or_fd),
+      SCM_SYSCALL (ans = read (scm_to_int (port_or_fd),
                               base + (cstart + offset) * sz,
                               (sz * (cend - offset))));
       if (ans == -1)
@@ -1639,22 +1595,22 @@ loop:
   if (SCM_TYP7 (v) == scm_tc7_bvect)
     ans *= SCM_LONG_BIT;
 
-  if (!SCM_EQ_P (v, ra) && !SCM_EQ_P (cra, ra))
+  if (!scm_is_eq (v, ra) && !scm_is_eq (cra, ra))
     scm_array_copy_x (cra, ra);
 
-  return SCM_MAKINUM (ans);
+  return scm_from_long (ans);
 }
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
            (SCM v, SCM port_or_fd, SCM start, SCM end),
-           "@deffnx primitive uniform-vector-write uve [port-or-fdes] [start] [end]\n"
+           "@deffnx {Scheme Procedure} uniform-vector-write uve [port-or-fdes] [start] [end]\n"
            "Writes all elements of @var{ura} as binary objects to\n"
            "@var{port-or-fdes}.\n\n"
            "The optional arguments @var{start}\n"
            "and @var{end} allow\n"
            "a specified region of a vector (or linearized array) to be written.\n\n"
-           "The number of objects actually written is returned. \n"
+           "The number of objects actually written is returned.\n"
            "@var{port-or-fdes} may be\n"
            "omitted, in which case it defaults to the value returned by\n"
            "@code{(current-output-port)}.")
@@ -1672,11 +1628,13 @@ SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
   if (SCM_UNBNDP (port_or_fd))
     port_or_fd = scm_cur_outp;
   else
-    SCM_ASSERT (SCM_INUMP (port_or_fd)
+    SCM_ASSERT (scm_is_integer (port_or_fd)
                || (SCM_OPOUTPORTP (port_or_fd)),
                port_or_fd, SCM_ARG2, FUNC_NAME);
-  vlen = SCM_INUM (scm_uniform_vector_length (v));
-
+  vlen = (SCM_TYP7 (v) == scm_tc7_smob
+         ? 0
+         : scm_to_long (scm_uniform_vector_length (v)));
+  
 loop:
   switch SCM_TYP7 (v)
     {
@@ -1686,8 +1644,8 @@ loop:
       SCM_ASRTGO (SCM_ARRAYP (v), badarg1);
       v = scm_ra2contig (v, 1);
       cstart = SCM_ARRAY_BASE (v);
-      vlen = SCM_ARRAY_DIMS (v)->inc
-       * (SCM_ARRAY_DIMS (v)->ubnd - SCM_ARRAY_DIMS (v)->lbnd + 1);
+      vlen = (SCM_ARRAY_DIMS (v)->inc
+             * (SCM_ARRAY_DIMS (v)->ubnd - SCM_ARRAY_DIMS (v)->lbnd + 1));
       v = SCM_ARRAY_V (v);
       goto loop;
     case scm_tc7_string:
@@ -1713,7 +1671,7 @@ loop:
       base = (char *) SCM_UVECTOR_BASE (v);
       sz = sizeof (short);
       break;
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       base = (char *) SCM_UVECTOR_BASE (v);
       sz = sizeof (long long);
@@ -1762,7 +1720,7 @@ loop:
     }
   else /* file descriptor.  */
     {
-      SCM_SYSCALL (ans = write (SCM_INUM (port_or_fd),
+      SCM_SYSCALL (ans = write (scm_to_int (port_or_fd),
                                base + (cstart + offset) * sz,
                                (sz * (cend - offset))));
       if (ans == -1)
@@ -1771,7 +1729,7 @@ loop:
   if (SCM_TYP7 (v) == scm_tc7_bvect)
     ans *= SCM_LONG_BIT;
 
-  return SCM_MAKINUM (ans);
+  return scm_from_long (ans);
 }
 #undef FUNC_NAME
 
@@ -1793,7 +1751,7 @@ SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0,
     unsigned long int count = 0;
     unsigned long int i = (SCM_BITVECTOR_LENGTH (bitvector) - 1) / SCM_LONG_BIT;
     unsigned long int w = SCM_UNPACK (SCM_VELTS (bitvector)[i]);
-    if (SCM_FALSEP (b)) {
+    if (scm_is_false (b)) {
       w = ~w;
     };
     w <<= SCM_LONG_BIT - 1 - ((SCM_BITVECTOR_LENGTH (bitvector) - 1) % SCM_LONG_BIT);
@@ -1803,11 +1761,11 @@ SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0,
        w >>= 4;
       }
       if (i == 0) {
-       return SCM_MAKINUM (count);
+       return scm_from_ulong (count);
       } else {
        --i;
        w = SCM_UNPACK (SCM_VELTS (bitvector)[i]);
-       if (SCM_FALSEP (b)) {
+       if (scm_is_false (b)) {
          w = ~w;
        }
       }
@@ -1819,9 +1777,15 @@ SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0,
 
 SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
            (SCM item, SCM v, SCM k),
-           "Return the minimum index of an occurrence of @var{bool} in\n"
-           "@var{bv} which is at least @var{k}.  If no @var{bool} occurs\n"
-           "within the specified range @code{#f} is returned.")
+           "Return the index of the first occurrance of @var{item} in bit\n"
+           "vector @var{v}, starting from @var{k}.  If there is no\n"
+           "@var{item} entry between @var{k} and the end of\n"
+           "@var{bitvector}, then return @code{#f}.  For example,\n"
+           "\n"
+           "@example\n"
+           "(bit-position #t #*000101 0)  @result{} 3\n"
+           "(bit-position #f #*0001111 3) @result{} #f\n"
+           "@end example")
 #define FUNC_NAME s_scm_bit_position
 {
   long i, lenw, xbits, pos;
@@ -1829,7 +1793,7 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
 
   SCM_VALIDATE_BOOL (1, item);
   SCM_ASSERT (SCM_BITVECTOR_P (v), v, SCM_ARG2, FUNC_NAME);
-  SCM_VALIDATE_INUM_COPY (3,k,pos);
+  pos = scm_to_long (k);
   SCM_ASSERT_RANGE (3, k, (pos <= SCM_BITVECTOR_LENGTH (v)) && (pos >= 0));
 
   if (pos == SCM_BITVECTOR_LENGTH (v))
@@ -1838,7 +1802,7 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
   lenw = (SCM_BITVECTOR_LENGTH (v) - 1) / SCM_LONG_BIT;   /* watch for part words */
   i = pos / SCM_LONG_BIT;
   w = SCM_UNPACK (SCM_VELTS (v)[i]);
-  if (SCM_FALSEP (item))
+  if (scm_is_false (item))
     w = ~w;
   xbits = (pos % SCM_LONG_BIT);
   pos -= xbits;
@@ -1853,17 +1817,17 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
          switch (w & 0x0f)
            {
            default:
-             return SCM_MAKINUM (pos);
+             return scm_from_long (pos);
            case 2:
            case 6:
            case 10:
            case 14:
-             return SCM_MAKINUM (pos + 1);
+             return scm_from_long (pos + 1);
            case 4:
            case 12:
-             return SCM_MAKINUM (pos + 2);
+             return scm_from_long (pos + 2);
            case 8:
-             return SCM_MAKINUM (pos + 3);
+             return scm_from_long (pos + 3);
            case 0:
              pos += 4;
              w >>= 4;
@@ -1872,7 +1836,7 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
        break;
       pos += SCM_LONG_BIT;
       w = SCM_UNPACK (SCM_VELTS (v)[i]);
-      if (SCM_FALSEP (item))
+      if (scm_is_false (item))
        w = ~w;
     }
   return SCM_BOOL_F;
@@ -1882,14 +1846,32 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
 
 SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
            (SCM v, SCM kv, SCM obj),
-           "If uve is a bit-vector @var{bv} and uve must be of the same\n"
-           "length.  If @var{bool} is @code{#t}, uve is OR'ed into\n"
-           "@var{bv}; If @var{bool} is @code{#f}, the inversion of uve is\n"
-           "AND'ed into @var{bv}.\n\n"
-           "If uve is a unsigned integer vector all the elements of uve\n"
-           "must be between 0 and the @code{length} of @var{bv}.  The bits\n"
-           "of @var{bv} corresponding to the indexes in uve are set to\n"
-           "@var{bool}.  The return value is unspecified.")
+           "Set entries of bit vector @var{v} to @var{obj}, with @var{kv}\n"
+           "selecting the entries to change.  The return value is\n"
+           "unspecified.\n"
+           "\n"
+           "If @var{kv} is a bit vector, then those entries where it has\n"
+           "@code{#t} are the ones in @var{v} which are set to @var{obj}.\n"
+           "@var{kv} and @var{v} must be the same length.  When @var{obj}\n"
+           "is @code{#t} it's like @var{kv} is OR'ed into @var{v}.  Or when\n"
+           "@var{obj} is @code{#f} it can be seen as an ANDNOT.\n"
+           "\n"
+           "@example\n"
+           "(define bv #*01000010)\n"
+           "(bit-set*! bv #*10010001 #t)\n"
+           "bv\n"
+           "@result{} #*11010011\n"
+           "@end example\n"
+           "\n"
+           "If @var{kv} is a uniform vector of unsigned long integers, then\n"
+           "they're indexes into @var{v} which are set to @var{obj}.\n"
+           "\n"
+           "@example\n"
+           "(define bv #*01000010)\n"
+           "(bit-set*! bv #u(5 2 7) #t)\n"
+           "bv\n"
+           "@result{} #*01100111\n"
+           "@end example")
 #define FUNC_NAME s_scm_bit_set_star_x
 {
   register long i, k, vlen;
@@ -1901,33 +1883,33 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
     badarg2:SCM_WRONG_TYPE_ARG (2, kv);
     case scm_tc7_uvect:
       vlen = SCM_BITVECTOR_LENGTH (v);
-      if (SCM_FALSEP (obj))
+      if (scm_is_false (obj))
        for (i = SCM_UVECTOR_LENGTH (kv); i;)
          {
            k = SCM_UNPACK (SCM_VELTS (kv)[--i]);
            if (k >= vlen)
-             scm_out_of_range (FUNC_NAME, SCM_MAKINUM (k));
-           SCM_BITVEC_CLR(v,k);
+             scm_out_of_range (FUNC_NAME, scm_from_long (k));
+           SCM_BITVEC_CLR(v, k);
          }
-      else if (SCM_EQ_P (obj, SCM_BOOL_T))
+      else if (scm_is_eq (obj, SCM_BOOL_T))
        for (i = SCM_UVECTOR_LENGTH (kv); i;)
          {
            k = SCM_UNPACK (SCM_VELTS (kv)[--i]);
            if (k >= vlen)
-             scm_out_of_range (FUNC_NAME, SCM_MAKINUM (k));
-           SCM_BITVEC_SET(v,k);
+             scm_out_of_range (FUNC_NAME, scm_from_long (k));
+           SCM_BITVEC_SET(v, k);
          }
       else
        badarg3:SCM_WRONG_TYPE_ARG (3, obj);
       break;
     case scm_tc7_bvect:
       SCM_ASSERT (SCM_BITVECTOR_LENGTH (v) == SCM_BITVECTOR_LENGTH (kv), v, SCM_ARG1, FUNC_NAME);
-      if (SCM_FALSEP (obj))
+      if (scm_is_false (obj))
        for (k = (SCM_BITVECTOR_LENGTH (v) + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-         SCM_UNPACK (SCM_VELTS (v)[k]) &= ~ SCM_UNPACK(SCM_VELTS (kv)[k]);
-      else if (SCM_EQ_P (obj, SCM_BOOL_T))
+         SCM_BITVECTOR_BASE (v) [k] &= ~SCM_BITVECTOR_BASE (kv) [k];
+      else if (scm_is_eq (obj, SCM_BOOL_T))
        for (k = (SCM_BITVECTOR_LENGTH (v) + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-         SCM_UNPACK (SCM_VELTS (v)[k]) |= SCM_UNPACK (SCM_VELTS (kv)[k]);
+         SCM_BITVECTOR_BASE (v) [k] |= SCM_BITVECTOR_BASE (kv) [k];
       else
        goto badarg3;
       break;
@@ -1939,11 +1921,23 @@ SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
 
 SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
            (SCM v, SCM kv, SCM obj),
-           "Return\n"
-           "@lisp\n"
-           "(bit-count (bit-set*! (if bool bv (bit-invert! bv)) uve #t) #t).\n"
-           "@end lisp\n"
-           "@var{bv} is not modified.")
+           "Return a count of how many entries in bit vector @var{v} are\n"
+           "equal to @var{obj}, with @var{kv} selecting the entries to\n"
+           "consider.\n"
+           "\n"
+           "If @var{kv} is a bit vector, then those entries where it has\n"
+           "@code{#t} are the ones in @var{v} which are considered.\n"
+           "@var{kv} and @var{v} must be the same length.\n"
+           "\n"
+           "If @var{kv} is a uniform vector of unsigned long integers, then\n"
+           "it's the indexes in @var{v} to consider.\n"
+           "\n"
+           "For example,\n"
+           "\n"
+           "@example\n"
+           "(bit-count* #*01110111 #*11001101 #t) @result{} 3\n"
+           "(bit-count* #*01110111 #u(7 0 4) #f)  @result{} 2\n"
+           "@end example")
 #define FUNC_NAME s_scm_bit_count_star
 {
   register long i, vlen, count = 0;
@@ -1959,22 +1953,22 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
         SCM_WRONG_TYPE_ARG (2, kv);
     case scm_tc7_uvect:
       vlen = SCM_BITVECTOR_LENGTH (v);
-      if (SCM_FALSEP (obj))
+      if (scm_is_false (obj))
        for (i = SCM_UVECTOR_LENGTH (kv); i;)
          {
            k = SCM_UNPACK (SCM_VELTS (kv)[--i]);
            if (k >= vlen)
-             scm_out_of_range (FUNC_NAME, SCM_MAKINUM (k));
-           if (!SCM_BITVEC_REF(v,k))
+             scm_out_of_range (FUNC_NAME, scm_from_long (k));
+           if (!SCM_BITVEC_REF(v, k))
              count++;
          }
-      else if (SCM_EQ_P (obj, SCM_BOOL_T))
+      else if (scm_is_eq (obj, SCM_BOOL_T))
        for (i = SCM_UVECTOR_LENGTH (kv); i;)
          {
            k = SCM_UNPACK (SCM_VELTS (kv)[--i]);
            if (k >= vlen)
-             scm_out_of_range (FUNC_NAME, SCM_MAKINUM (k));
-           if (SCM_BITVEC_REF (v,k))
+             scm_out_of_range (FUNC_NAME, scm_from_long (k));
+           if (SCM_BITVEC_REF (v, k))
              count++;
          }
       else
@@ -1984,8 +1978,8 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
       SCM_ASSERT (SCM_BITVECTOR_LENGTH (v) == SCM_BITVECTOR_LENGTH (kv), v, SCM_ARG1, FUNC_NAME);
       if (0 == SCM_BITVECTOR_LENGTH (v))
        return SCM_INUM0;
-      SCM_ASRTGO (SCM_BOOLP (obj), badarg3);
-      fObj = SCM_EQ_P (obj, SCM_BOOL_T);
+      SCM_ASRTGO (scm_is_bool (obj), badarg3);
+      fObj = scm_is_eq (obj, SCM_BOOL_T);
       i = (SCM_BITVECTOR_LENGTH (v) - 1) / SCM_LONG_BIT;
       k = SCM_UNPACK (SCM_VELTS (kv)[i]) & (fObj ? SCM_UNPACK (SCM_VELTS (v)[i]) : ~ SCM_UNPACK (SCM_VELTS (v)[i]));
       k <<= SCM_LONG_BIT - 1 - ((SCM_BITVECTOR_LENGTH (v) - 1) % SCM_LONG_BIT);
@@ -1994,20 +1988,21 @@ SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
          for (; k; k >>= 4)
            count += cnt_tab[k & 0x0f];
          if (0 == i--)
-           return SCM_MAKINUM (count);
+           return scm_from_long (count);
 
          /* urg. repetitive (see above.) */
          k = SCM_UNPACK (SCM_VELTS (kv)[i]) & (fObj ? SCM_UNPACK(SCM_VELTS (v)[i]) : ~SCM_UNPACK (SCM_VELTS (v)[i]));
        }
     }
-  return SCM_MAKINUM (count);
+  return scm_from_long (count);
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_bit_invert_x, "bit-invert!", 1, 0, 0, 
            (SCM v),
-           "Modifies @var{bv} by replacing each element with its negation.")
+           "Modify the bit vector @var{v} by replacing each element with\n"
+           "its negation.")
 #define FUNC_NAME s_scm_bit_invert_x
 {
   long int k;
@@ -2016,7 +2011,7 @@ SCM_DEFINE (scm_bit_invert_x, "bit-invert!", 1, 0, 0,
 
   k = SCM_BITVECTOR_LENGTH (v);
   for (k = (k + SCM_LONG_BIT - 1) / SCM_LONG_BIT; k--;)
-    SCM_UNPACK (SCM_VELTS (v)[k]) = ~SCM_UNPACK (SCM_VELTS (v)[k]);
+    SCM_BITVECTOR_BASE (v) [k] = ~SCM_BITVECTOR_BASE (v) [k];
 
   return SCM_UNSPECIFIED;
 }
@@ -2055,7 +2050,7 @@ scm_istr2bve (char *str, long len)
 
 
 static SCM 
-ra2l (SCM ra,unsigned long base,unsigned long k)
+ra2l (SCM ra, unsigned long base, unsigned long k)
 {
   register SCM res = SCM_EOL;
   register long inc = SCM_ARRAY_DIMS (ra)[k].inc;
@@ -2076,7 +2071,7 @@ ra2l (SCM ra,unsigned long base,unsigned long k)
     do
       {
        i -= inc;
-       res = scm_cons (scm_uniform_vector_ref (SCM_ARRAY_V (ra), SCM_MAKINUM (i)), res);
+       res = scm_cons (scm_uniform_vector_ref (SCM_ARRAY_V (ra), scm_from_size_t (i)), res);
       }
     while (i != base);
   return res;
@@ -2110,9 +2105,9 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
        register unsigned long mask;
        for (k = (SCM_BITVECTOR_LENGTH (v) - 1) / SCM_LONG_BIT; k > 0; k--)
          for (mask = 1UL << (SCM_LONG_BIT - 1); mask; mask >>= 1)
-           res = scm_cons (SCM_BOOL(((long *) data)[k] & mask), res);
+           res = scm_cons (scm_from_bool(((long *) data)[k] & mask), res);
        for (mask = 1L << ((SCM_BITVECTOR_LENGTH (v) % SCM_LONG_BIT) - 1); mask; mask >>= 1)
-         res = scm_cons (SCM_BOOL(((long *) data)[k] & mask), res);
+         res = scm_cons (scm_from_bool(((long *) data)[k] & mask), res);
        return res;
       }
     case scm_tc7_byvect:
@@ -2120,21 +2115,21 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
        signed char *data = (signed char *) SCM_VELTS (v);
        unsigned long k = SCM_UVECTOR_LENGTH (v);
        while (k != 0)
-         res = scm_cons (SCM_MAKINUM (data[--k]), res);
+         res = scm_cons (scm_from_schar (data[--k]), res);
        return res;
       }
     case scm_tc7_uvect:
       {
-       long *data = (long *)SCM_VELTS(v);
+       unsigned long *data = (unsigned long *)SCM_VELTS(v);
        for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-         res = scm_cons(scm_ulong2num(data[k]), res);
+         res = scm_cons(scm_from_ulong (data[k]), res);
        return res;
       }
     case scm_tc7_ivect:
       {
        long *data = (long *)SCM_VELTS(v);
        for (k = SCM_UVECTOR_LENGTH(v) - 1; k >= 0; k--)
-         res = scm_cons(scm_long2num(data[k]), res);
+         res = scm_cons(scm_from_long (data[k]), res);
        return res;
       }
     case scm_tc7_svect:
@@ -2144,7 +2139,7 @@ SCM_DEFINE (scm_array_to_list, "array->list", 1, 0, 0,
          res = scm_cons(scm_short2num (data[k]), res);
        return res;
       }
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       {
        long long *data = (long long *)SCM_VELTS(v);
@@ -2183,7 +2178,7 @@ static int l2ra(SCM lst, SCM ra, unsigned long base, unsigned long k);
 
 SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
            (SCM ndim, SCM prot, SCM lst),
-           "@deffnx procedure list->uniform-vector prot lst\n"
+           "@deffnx {Scheme Procedure} list->uniform-vector prot lst\n"
            "Return a uniform array of the type indicated by prototype\n"
            "@var{prot} with elements the same as those of @var{lst}.\n"
            "Elements must be of the appropriate type, no coercions are\n"
@@ -2195,12 +2190,12 @@ SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
   SCM ra;
   unsigned long k;
   long n;
-  SCM_VALIDATE_INUM_COPY (1,ndim,k);
+  k = scm_to_ulong (ndim);
   while (k--)
     {
       n = scm_ilength (row);
       SCM_ASSERT (n >= 0, lst, SCM_ARG3, FUNC_NAME);
-      shp = scm_cons (SCM_MAKINUM (n), shp);
+      shp = scm_cons (scm_from_long (n), shp);
       if (SCM_NIMP (row))
        row = SCM_CAR (row);
     }
@@ -2214,15 +2209,16 @@ SCM_DEFINE (scm_list_to_uniform_array, "list->uniform-array", 3, 0, 0,
     }
   if (!SCM_ARRAYP (ra))
     {
-      unsigned long int length = SCM_INUM (scm_uniform_vector_length (ra));
+      unsigned long length = scm_to_ulong (scm_uniform_vector_length (ra));
       for (k = 0; k < length; k++, lst = SCM_CDR (lst))
-       scm_array_set_x (ra, SCM_CAR (lst), SCM_MAKINUM (k));
+       scm_array_set_x (ra, SCM_CAR (lst), scm_from_ulong (k));
       return ra;
     }
   if (l2ra (lst, ra, SCM_ARRAY_BASE (ra), 0))
     return ra;
   else
-    badlst:SCM_MISC_ERROR ("Bad scm_array contents list: ~S", SCM_LIST1 (lst));
+    badlst:SCM_MISC_ERROR ("Bad scm_array contents list: ~S",
+                          scm_list_1 (lst));
 }
 #undef FUNC_NAME
 
@@ -2238,26 +2234,26 @@ l2ra (SCM lst, SCM ra, unsigned long base, unsigned long k)
     {
       while (n--)
        {
-         if (SCM_IMP (lst) || SCM_NCONSP (lst))
+         if (!SCM_CONSP (lst))
            return 0;
          ok = ok && l2ra (SCM_CAR (lst), ra, base, k + 1);
          base += inc;
          lst = SCM_CDR (lst);
        }
-      if (SCM_NNULLP (lst))
+      if (!SCM_NULLP (lst))
  return 0;
     }
   else
     {
       while (n--)
        {
-         if (SCM_IMP (lst) || SCM_NCONSP (lst))
+         if (!SCM_CONSP (lst))
            return 0;
-         scm_array_set_x (SCM_ARRAY_V (ra), SCM_CAR (lst), SCM_MAKINUM (base));
+         scm_array_set_x (SCM_ARRAY_V (ra), SCM_CAR (lst), scm_from_ulong (base));
          base += inc;
          lst = SCM_CDR (lst);
        }
-      if (SCM_NNULLP (lst))
+      if (!SCM_NULLP (lst))
        return 0;
     }
   return ok;
@@ -2265,12 +2261,12 @@ l2ra (SCM lst, SCM ra, unsigned long base, unsigned long k)
 
 
 static void 
-rapr1 (SCM ra,unsigned long j,unsigned long k,SCM port,scm_print_state *pstate)
+rapr1 (SCM ra, unsigned long j, unsigned long k, SCM port, scm_print_state *pstate)
 {
   long inc = 1;
   long n = (SCM_TYP7 (ra) == scm_tc7_smob
            ? 0
-           : SCM_INUM (scm_uniform_vector_length (ra)));
+           : scm_to_long (scm_uniform_vector_length (ra)));
   int enclosed = 0;
 tail:
   switch SCM_TYP7 (ra)
@@ -2320,7 +2316,7 @@ tail:
     default:
       /* scm_tc7_bvect and scm_tc7_llvect only?  */
       if (n-- > 0)
-       scm_iprin1 (scm_uniform_vector_ref (ra, SCM_MAKINUM (j)), port, pstate);
+       scm_iprin1 (scm_uniform_vector_ref (ra, scm_from_ulong (j)), port, pstate);
       for (j += inc; n-- > 0; j += inc)
        {
          scm_putc (' ', port);
@@ -2469,13 +2465,13 @@ tail:
          }
       }
     case scm_tc7_bvect:
-      if (SCM_EQ_P (exp, v))
+      if (scm_is_eq (exp, v))
        {                       /* a uve, not an scm_array */
          register long i, j, w;
          scm_putc ('*', port);
          for (i = 0; i < (SCM_BITVECTOR_LENGTH (exp)) / SCM_LONG_BIT; i++)
            {
-             scm_bits_t w = SCM_UNPACK (SCM_VELTS (exp)[i]);
+             scm_t_bits w = SCM_UNPACK (SCM_VELTS (exp)[i]);
              for (j = SCM_LONG_BIT; j; j--)
                {
                  scm_putc (w & 1 ? '1' : '0', port);
@@ -2512,7 +2508,7 @@ tail:
     case scm_tc7_svect:
       scm_putc ('h', port);
       break;
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       scm_putc ('l', port);
       break;
@@ -2563,19 +2559,19 @@ loop:
     case scm_tc7_byvect:
       return SCM_MAKE_CHAR ('\0');
     case scm_tc7_uvect:
-      return SCM_MAKINUM (1L);
+      return scm_from_int (1);
     case scm_tc7_ivect:
-      return SCM_MAKINUM (-1L);
+      return scm_from_int (-1);
     case scm_tc7_svect:
       return scm_str2symbol ("s");
-#ifdef HAVE_LONG_LONGS
+#if SCM_SIZEOF_LONG_LONG != 0
     case scm_tc7_llvect:
       return scm_str2symbol ("l");
 #endif
     case scm_tc7_fvect:
       return scm_make_real (1.0);
     case scm_tc7_dvect:
-      return scm_make_real (1.0 / 3.0);
+      return exactly_one_third;
     case scm_tc7_cvect:
       return scm_make_complex (0.0, 1.0);
     }
@@ -2593,9 +2589,11 @@ array_mark (SCM ptr)
 static size_t
 array_free (SCM ptr)
 {
-  scm_must_free (SCM_ARRAY_MEM (ptr));
-  return sizeof (scm_array_t) +
-    SCM_ARRAY_NDIM (ptr) * sizeof (scm_array_dim_t);
+  scm_gc_free (SCM_ARRAY_MEM (ptr),
+              (sizeof (scm_t_array) 
+               + SCM_ARRAY_NDIM (ptr) * sizeof (scm_t_array_dim)),
+              "array");
+  return 0;
 }
 
 void
@@ -2606,10 +2604,10 @@ scm_init_unif ()
   scm_set_smob_free (scm_tc16_array, array_free);
   scm_set_smob_print (scm_tc16_array, scm_raprin1);
   scm_set_smob_equalp (scm_tc16_array, scm_array_equal_p);
+  exactly_one_third = scm_permanent_object (scm_make_ratio (scm_from_int (1),
+                                                            scm_from_int (3)));
   scm_add_feature ("array");
-#ifndef SCM_MAGIC_SNARFER
 #include "libguile/unif.x"
-#endif
 }
 
 /*