fix string-filter and string-delete argument order
authorAndy Wingo <wingo@pobox.com>
Fri, 19 Nov 2010 16:08:36 +0000 (17:08 +0100)
committerAndy Wingo <wingo@pobox.com>
Fri, 19 Nov 2010 16:08:36 +0000 (17:08 +0100)
* libguile/srfi-13.h:
* libguile/srfi-13.c (scm_string_filter, scm_string_delete): Swap
  char_pred and s argument order, to comply with SRFI-13. There is a
  back-compat shim that will detect programs that used the old,
  erroneous interface, while giving a warning.

* doc/ref/api-data.texi: Update docs.

doc/ref/api-data.texi
libguile/srfi-13.c
libguile/srfi-13.h

index 6dcab05..14b81f5 100755 (executable)
@@ -3850,8 +3850,8 @@ If @var{start} or @var{end} indices are provided, they restrict
 of @var{s}.
 @end deffn
 
-@deffn {Scheme Procedure} string-filter s char_pred [start [end]]
-@deffnx {C Function} scm_string_filter (s, char_pred, start, end)
+@deffn {Scheme Procedure} string-filter char_pred s [start [end]]
+@deffnx {C Function} scm_string_filter (char_pred, s, start, end)
 Filter the string @var{s}, retaining only those characters which
 satisfy @var{char_pred}.
 
@@ -3860,8 +3860,8 @@ a predicate, if it is a character, it is tested for equality and if it
 is a character set, it is tested for membership.
 @end deffn
 
-@deffn {Scheme Procedure} string-delete s char_pred [start [end]]
-@deffnx {C Function} scm_string_delete (s, char_pred, start, end)
+@deffn {Scheme Procedure} string-delete char_pred s [start [end]]
+@deffnx {C Function} scm_string_delete (char_pred, s, start, end)
 Delete characters satisfying @var{char_pred} from @var{s}.
 
 If @var{char_pred} is a procedure, it is applied to each character as
index e9bf94e..afeb804 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "libguile.h"
 
+#include <libguile/deprecation.h>
 #include "libguile/srfi-13.h"
 #include "libguile/srfi-14.h"
 
@@ -3033,7 +3034,7 @@ SCM_DEFINE (scm_string_split, "string-split", 2, 0, 0,
 
 
 SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
-           (SCM s, SCM char_pred, SCM start, SCM end),
+           (SCM char_pred, SCM s, SCM start, SCM end),
            "Filter the string @var{s}, retaining only those characters\n"
            "which satisfy @var{char_pred}.\n"
            "\n"
@@ -3047,7 +3048,21 @@ SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
   SCM result;
   size_t idx;
 
-  MY_VALIDATE_SUBSTRING_SPEC (1, s,
+  if (scm_is_string (char_pred))
+    {
+      SCM tmp;
+      
+      scm_c_issue_deprecation_warning
+        ("Guile used to use the wrong argument order for string-filter.\n"
+         "This call to string-filter had the arguments in the wrong order.\n"
+         "See SRFI-13 for more details. At some point we will remove this hack.");
+
+      tmp = char_pred;
+      char_pred = s;
+      s = tmp;
+    }
+
+  MY_VALIDATE_SUBSTRING_SPEC (2, s,
                              3, start, cstart,
                              4, end, cend);
 
@@ -3130,7 +3145,7 @@ SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
       SCM ls = SCM_EOL;
 
       SCM_ASSERT (scm_is_true (scm_procedure_p (char_pred)),
-                  char_pred, SCM_ARG2, FUNC_NAME);
+                  char_pred, SCM_ARG1, FUNC_NAME);
       idx = cstart;
       while (idx < cend)
        {
@@ -3151,7 +3166,7 @@ SCM_DEFINE (scm_string_filter, "string-filter", 2, 2, 0,
 
 
 SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
-           (SCM s, SCM char_pred, SCM start, SCM end),
+           (SCM char_pred, SCM s, SCM start, SCM end),
            "Delete characters satisfying @var{char_pred} from @var{s}.\n"
            "\n"
            "If @var{char_pred} is a procedure, it is applied to each\n"
@@ -3164,7 +3179,21 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
   SCM result;
   size_t idx;
 
-  MY_VALIDATE_SUBSTRING_SPEC (1, s,
+  if (scm_is_string (char_pred))
+    {
+      SCM tmp;
+      
+      scm_c_issue_deprecation_warning
+        ("Guile used to use the wrong argument order for string-delete.\n"
+         "This call to string-filter had the arguments in the wrong order.\n"
+         "See SRFI-13 for more details. At some point we will remove this hack.");
+
+      tmp = char_pred;
+      char_pred = s;
+      s = tmp;
+    }
+
+  MY_VALIDATE_SUBSTRING_SPEC (2, s,
                              3, start, cstart,
                              4, end, cend);
 
@@ -3265,7 +3294,7 @@ SCM_DEFINE (scm_string_delete, "string-delete", 2, 2, 0,
     {
       SCM ls = SCM_EOL;
       SCM_ASSERT (scm_is_true (scm_procedure_p (char_pred)),
-                  char_pred, SCM_ARG2, FUNC_NAME);
+                  char_pred, SCM_ARG1, FUNC_NAME);
 
       idx = cstart;
       while (idx < cend)
index 478a55d..f63239a 100644 (file)
@@ -3,7 +3,7 @@
 
 /* srfi-13.c --- SRFI-13 procedures for Guile
  *
- *     Copyright (C) 2001, 2004, 2006, 2008 Free Software Foundation, Inc.
+ *     Copyright (C) 2001, 2004, 2006, 2008, 2010 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -111,8 +111,8 @@ SCM_API SCM scm_string_xcopy_x (SCM target, SCM tstart, SCM s, SCM sfrom, SCM st
 SCM_API SCM scm_string_replace (SCM s1, SCM s2, SCM start1, SCM end1, SCM start2, SCM end2);
 SCM_API SCM scm_string_tokenize (SCM s, SCM token_char, SCM start, SCM end);
 SCM_API SCM scm_string_split (SCM s, SCM chr);
-SCM_API SCM scm_string_filter (SCM s, SCM char_pred, SCM start, SCM end);
-SCM_API SCM scm_string_delete (SCM s, SCM char_pred, SCM start, SCM end);
+SCM_API SCM scm_string_filter (SCM char_pred, SCM s, SCM start, SCM end);
+SCM_API SCM scm_string_delete (SCM char_pred, SCM s, SCM start, SCM end);
 
 SCM_INTERNAL void scm_init_srfi_13 (void);
 SCM_INTERNAL void scm_init_srfi_13_14 (void);