guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

srfi-13 string-any tail call


From: Kevin Ryde
Subject: srfi-13 string-any tail call
Date: Tue, 07 Dec 2004 08:08:23 +1100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

I'm thinking of the following wrapper around the string-any C code to
get a tail call on the last pred test, per the srfi-13 spec.  It's not
too pretty, but at least it'll be right.  I guess in the head it could
tie into eval now that string-any is in the core.

(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))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]