[uim-commit] r2815 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Fri Jan 6 14:33:04 PST 2006


Author: yamaken
Date: 2006-01-06 14:33:01 -0800 (Fri, 06 Jan 2006)
New Revision: 2815

Modified:
   branches/r5rs/sigscheme/operations.c
   branches/r5rs/sigscheme/sigscheme.h
Log:
* sigscheme/operations.c
  - (TERMINATOR_LEN): New macro
  - (scm_length):
    * Fix desciption error for meaning of -1
    * Rename some elements to make meaningful
* sigscheme/sigscheme.h
  - (SCM_LISTLEN_DOTTED): Replace unneeded abs(3) with simple nagation
  - (SCM_LISTLEN_BEFORE_DOT): Correct the comment


Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2006-01-06 21:42:44 UTC (rev 2814)
+++ branches/r5rs/sigscheme/operations.c	2006-01-06 22:33:01 UTC (rev 2815)
@@ -808,30 +808,37 @@
  * 2006-01-05 YamaKen  Return dot list length and circular indication.
  *
  */
-/* Returns -1 for non-list, as zero length improper list. */
+/* Returns -1 as one length improper list for non-list obj. */
 int
 scm_length(ScmObj lst)
 {
     ScmObj slow;
-    int len;
+    int proper_len;
 
-    for (len = 0, slow = lst;;) {
+#define TERMINATOR_LEN 1
+
+    for (proper_len = 0, slow = lst;;) {
         if (NULLP(lst)) break;
-        if (!CONSP(lst))             return SCM_LISTLEN_ENCODE_DOTTED(len + 1);
-        if (len != 0 && lst == slow) return SCM_LISTLEN_ENCODE_CIRCULAR(len);
+        if (!CONSP(lst))
+            return SCM_LISTLEN_ENCODE_DOTTED(proper_len + TERMINATOR_LEN);
+        if (proper_len != 0 && lst == slow)
+            return SCM_LISTLEN_ENCODE_CIRCULAR(proper_len);
 
         lst = CDR(lst);
-        len++;
+        proper_len++;
         if (NULLP(lst)) break;
-        if (!CONSP(lst)) return SCM_LISTLEN_ENCODE_DOTTED(len + 1);
-        if (lst == slow) return SCM_LISTLEN_ENCODE_CIRCULAR(len);
+        if (!CONSP(lst))
+            return SCM_LISTLEN_ENCODE_DOTTED(proper_len + TERMINATOR_LEN);
+        if (lst == slow)
+            return SCM_LISTLEN_ENCODE_CIRCULAR(proper_len);
 
         lst = CDR(lst);
         slow = CDR(slow);
-        len++;
+        proper_len++;
     }
 
-    return len;
+    return proper_len;
+#undef TERMINATOR_LEN
 }
 
 ScmObj

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2006-01-06 21:42:44 UTC (rev 2814)
+++ branches/r5rs/sigscheme/sigscheme.h	2006-01-06 22:33:01 UTC (rev 2815)
@@ -165,8 +165,8 @@
 #define SCM_LISTLEN_ERRORP          SCM_LISTLEN_CIRCULARP
 #define SCM_LISTLEN_DOTTEDP(len)    ((len) < 0                               \
                                      && !SCM_LISTLEN_CIRCULARP(len))
-#define SCM_LISTLEN_DOTTED(len)     (abs(len))
-#define SCM_LISTLEN_BEFORE_DOT(len) (~(len))  /* abs(len) - 1 */
+#define SCM_LISTLEN_DOTTED(len)     (-(len))
+#define SCM_LISTLEN_BEFORE_DOT(len) (~(len))  /* -(len) - 1 */
 
 #define SCM_EVAL(obj, env) (scm_eval((obj), (env)))
 



More information about the uim-commit mailing list