diff --git a/srfi/srfi-13.c b/srfi/srfi-13.c index d4d7e3e39..445178634 100644 --- a/srfi/srfi-13.c +++ b/srfi/srfi-13.c @@ -52,7 +52,7 @@ #include "srfi-13.h" #include "srfi-14.h" -SCM_DEFINE (scm_string_any, "string-any", 2, 2, 0, +SCM_DEFINE (scm_string_any, "string-any-c-code", 2, 2, 0, (SCM char_pred, SCM s, SCM start, SCM end), "Check if the predicate @var{pred} is true for any character in\n" "the string @var{s}, proceeding from left (index @var{start}) to\n" @@ -99,7 +99,7 @@ SCM_DEFINE (scm_string_any, "string-any", 2, 2, 0, #undef FUNC_NAME -SCM_DEFINE (scm_string_every, "string-every", 2, 2, 0, +SCM_DEFINE (scm_string_every, "string-every-c-code", 2, 2, 0, (SCM char_pred, SCM s, SCM start, SCM end), "Check if the predicate @var{pred} is true for every character\n" "in the string @var{s}, proceeding from left (index @var{start})\n" diff --git a/srfi/srfi-13.scm b/srfi/srfi-13.scm index 1b9baa7f3..002f390dc 100644 --- a/srfi/srfi-13.scm +++ b/srfi/srfi-13.scm @@ -1,6 +1,6 @@ ;;; srfi-13.scm --- String Library -;; Copyright (C) 2001, 2002 Free Software Foundation, Inc. +;; Copyright (C) 2001, 2002, 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 @@ -158,6 +158,32 @@ (load-extension "libguile-srfi-srfi-13-14-v-1" "scm_init_srfi_13") +;; this is scheme wrapping the C code so the final pred call is a tail call +(define (string-any char_pred s . rest) + (let ((start (if (null? rest) + 0 (car rest))) + (end (if (or (null? rest) (null? (cdr rest))) + (string-length s) (cadr rest)))) + (if (and (procedure? char_pred) + (> end start) + (<= end (string-length s))) ;; let c-code handle range error + (or (string-any-c-code char_pred s start (1- end)) + (char_pred (string-ref s (1- end)))) + (string-any-c-code char_pred s start end)))) + +;; this is scheme wrapping the C code so the final pred call is a tail call +(define (string-every char_pred s . rest) + (let ((start (if (null? rest) + 0 (car rest))) + (end (if (or (null? rest) (null? (cdr rest))) + (string-length s) (cadr rest)))) + (if (and (procedure? char_pred) + (> end start) + (<= end (string-length s))) ;; let c-code handle range error + (and (string-every-c-code char_pred s start (1- end)) + (char_pred (string-ref s (1- end)))) + (string-every-c-code char_pred s start end)))) + (define string-hash (lambda (s . rest) (let ((bound (if (pair? rest)