This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

patches + Inconsistency with append!


Hi!

There's a difference between how append and append! handle improper lists
that are given as parameters:

---------------------
guile> (define foo (cons 1 2))
guile> (append foo (list 3))

Backtrace:
0* [append (1 . 2) (3)]

ERROR: In procedure append in expression (append foo (list 3)):
ERROR: Wrong type argument: 2
ABORT: (wrong-type-arg)
---------------------

But:

---------------------
guile> (define foo (cons 1 2))
guile> (append! foo (list 3))
(1 3)
---------------------

Is this inconsistency OK?  If so, this should be made explicit in the
documentation of append!

Below you find some minor patches regarding the following aspects:

list.c
* Put some variable initialization code at the point of declaration.
* Added a comment for list*
* Formatting changes

load.c
* Use SCM_NNULLP to make sure the end of a list is not reached yet.


Best regards
Dirk Herrmann



Index: libguile/list.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/list.c,v
retrieving revision 1.28
diff -u -p -r1.28 list.c
--- list.c	2000/01/18 13:09:54	1.28
+++ list.c	2000/01/20 17:24:28
@@ -61,17 +61,14 @@
 
 /* creating lists */
 
-/* SCM_P won't help us deal with varargs here.  */
 SCM
 scm_listify (SCM elt, ...)
 {
   va_list foo;
-  SCM answer;
-  SCM *pos;
+  SCM answer = SCM_EOL;
+  SCM *pos = &answer;
 
   var_start (foo, elt);
-  answer = SCM_EOL;
-  pos = &answer;
   while (elt != SCM_UNDEFINED)
     {
       *pos = scm_cons (elt, SCM_EOL);
@@ -94,7 +91,7 @@ SCM_DEFINE (scm_list, "list", 0, 0, 1, 
 
 SCM_DEFINE (scm_list_star, "list*", 1, 0, 1, 
             (SCM arg, SCM rest),
-"")
+	    "Return an improper list of the arguments.")
 #define FUNC_NAME s_scm_list_star
 {
   if (SCM_NNULLP (rest))
@@ -120,16 +117,17 @@ SCM_DEFINE (scm_null_p, "null?", 1, 0, 0
 "")
 #define FUNC_NAME s_scm_null_p
 {
-  return SCM_BOOL(SCM_NULLP(x));
+  return SCM_BOOL (SCM_NULLP (x));
 }
 #undef FUNC_NAME
 
+
 SCM_DEFINE (scm_list_p, "list?", 1, 0, 0, 
            (SCM x),
 "")
 #define FUNC_NAME s_scm_list_p
 {
-  return SCM_BOOL(scm_ilength(x)>=0);
+  return SCM_BOOL (scm_ilength (x) >= 0);
 }
 #undef FUNC_NAME
 
@@ -164,6 +162,7 @@ scm_ilength(SCM sx)
   return -1;
 }
 
+
 SCM_DEFINE (scm_length, "length", 1, 0, 0, 
            (SCM lst),
 "")
Index: libguile/load.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/load.c,v
retrieving revision 1.35
diff -u -p -r1.35 load.c
--- load.c	2000/01/18 11:24:03	1.35
+++ load.c	2000/01/20 17:24:28
@@ -285,7 +285,7 @@ SCM_DEFINE (scm_search_path, "search-pat
     SCM walk;
 
     max_path_len = 0;
-    for (walk = path; SCM_NIMP (walk); walk = SCM_CDR (walk))
+    for (walk = path; SCM_NNULLP (walk); walk = SCM_CDR (walk))
       {
 	SCM elt = SCM_CAR (walk);
 	SCM_ASSERT (SCM_ROSTRINGP (elt), elt,
@@ -324,7 +324,7 @@ SCM_DEFINE (scm_search_path, "search-pat
     SCM walk;
 
     max_ext_len = 0;
-    for (walk = extensions; SCM_NIMP (walk); walk = SCM_CDR (walk))
+    for (walk = extensions; SCM_NNULLP (walk); walk = SCM_CDR (walk))
       {
 	SCM elt = SCM_CAR (walk);
 	SCM_ASSERT (SCM_ROSTRINGP (elt), elt,
@@ -348,7 +348,7 @@ SCM_DEFINE (scm_search_path, "search-pat
 
     /* Try every path element.  At this point, we know the path is a
        proper list of strings.  */
-    for (; SCM_NIMP (path); path = SCM_CDR (path))
+    for (; SCM_NNULLP (path); path = SCM_CDR (path))
       {
 	int len;
 	SCM dir = SCM_CAR (path);
@@ -364,7 +364,7 @@ SCM_DEFINE (scm_search_path, "search-pat
 
 	/* Try every extension.  At this point, we know the extension
 	   list is a proper, nonempty list of strings.  */
-	for (exts = extensions; SCM_NIMP (exts); exts = SCM_CDR (exts))
+	for (exts = extensions; SCM_NNULLP (exts); exts = SCM_CDR (exts))
 	  {
 	    SCM ext = SCM_CAR (exts);
 	    int ext_len = SCM_ROLENGTH (ext);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]