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

yamaken at freedesktop.org yamaken at freedesktop.org
Thu Jan 5 01:17:10 PST 2006


Author: yamaken
Date: 2006-01-05 01:17:05 -0800 (Thu, 05 Jan 2006)
New Revision: 2801

Modified:
   branches/r5rs/sigscheme/operations.c
   branches/r5rs/sigscheme/sigschemeinternal.h
Log:
* sigscheme/sigschemeinternal.h
  - (SCM_LISTLEN_CIRCULARP, SCM_LISTLEN_DOTP, SCM_LISTLEN_BEFORE_DOT):
    New macro
* sigscheme/operations.c
  - (LISTLEN_ENCODE_DOT, LISTLEN_ENCODE_CIRCULAR): New macro
  - (scm_length): Return dot list length and circular indication


Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2006-01-05 04:23:28 UTC (rev 2800)
+++ branches/r5rs/sigscheme/operations.c	2006-01-05 09:17:05 UTC (rev 2801)
@@ -802,25 +802,34 @@
  * This function is ported from Gauche, by Shiro Kawai(shiro at acm.org)
  */
 /* FIXME: Insert its copyright and license into this file properly */
+/*
+ * ChangeLog:
+ *
+ * 2006-01-05 YamaKen  Return dot list length and circular indication.
+ *
+ */
 int
 scm_length(ScmObj lst)
 {
     ScmObj slow;
     int len;
 
+#define LISTLEN_ENCODE_DOT(len)      (-(len))
+#define LISTLEN_ENCODE_CIRCULAR(len) (INT_MIN)
+
     slow = lst;
     len = 0;
 
     for (;;) {
         if (NULLP(lst)) break;
-        if (!CONSP(lst)) return -1;
-        if (len != 0 && lst == slow) return -1; /* circular */
+        if (!CONSP(lst)) return LISTLEN_ENCODE_DOT(len);
+        if (len != 0 && lst == slow) return LISTLEN_ENCODE_CIRCULAR(len);
 
         lst = CDR(lst);
         len++;
         if (NULLP(lst)) break;
-        if (!CONSP(lst)) return -1;
-        if (lst == slow) return -1; /* circular */
+        if (!CONSP(lst)) return LISTLEN_ENCODE_DOT(len);
+        if (lst == slow) return LISTLEN_ENCODE_CIRCULAR(len);
 
         lst = CDR(lst);
         slow = CDR(slow);
@@ -828,6 +837,8 @@
     }
 
     return len;
+#undef LISTLEN_ENCODE_DOT
+#undef LISTLEN_ENCODE_CIRCULAR
 }
 
 ScmObj

Modified: branches/r5rs/sigscheme/sigschemeinternal.h
===================================================================
--- branches/r5rs/sigscheme/sigschemeinternal.h	2006-01-05 04:23:28 UTC (rev 2800)
+++ branches/r5rs/sigscheme/sigschemeinternal.h	2006-01-05 09:17:05 UTC (rev 2801)
@@ -37,6 +37,7 @@
 /*=======================================
    System Include
 =======================================*/
+#include <limits.h>
 #include <stdarg.h>
 
 /*=======================================
@@ -345,6 +346,12 @@
 /* error handlings */
 #define SCM_ERR_HEADER "Error: "
 
+/* result decoders for scm_length() */
+#define SCM_LISTLEN_CIRCULARP(len)   ((len) == INT_MIN)
+#define SCM_LISTLEN_DOTP(len)        ((len) < 0                              \
+                                      && !SCM_LISTLEN_CIRCULARP(len))
+#define SCM_LISTLEN_BEFORE_DOT(len)  (~(len))  /* abs(len) - 1 */
+
 /*=======================================
    List Constructor
 =======================================*/



More information about the uim-commit mailing list