mes: Add string-rindex.

* module/srfi/srfi-13.mes (string-rindex): New function.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-19 00:41:01 +02:00
parent 20b3c349bf
commit dda7a7cd62

View file

@ -74,3 +74,14 @@
(if (null? lst) #f
(if (pred (car lst)) i
(loop (cdr lst) (1+ i)))))))
(define (string-rindex s pred . rest)
(let* ((start (and (pair? rest) (car rest)))
(end (and start (pair? (cdr rest)) (cadr rest)))
(pred (if (char? pred) (lambda (c) (eq? c pred)) pred)))
(if start (error "string-rindex: not supported: start=" start))
(if end (error "string-rindex: not supported: end=" end))
(let loop ((lst (reverse (string->list s))) (i (1- (string-length s))))
(if (null? lst) #f
(if (pred (car lst)) i
(loop (cdr lst) (1- i)))))))