From 20b3c349bf2023eb7a887536d40bd0c467114686 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 19 May 2017 00:51:23 +0200 Subject: [PATCH] mes: Support predicate with string-index. * module/srfi/srfi-13.mes (string-index): Support predicate. --- module/srfi/srfi-13.mes | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/srfi/srfi-13.mes b/module/srfi/srfi-13.mes index 98b2d667..9579854d 100644 --- a/module/srfi/srfi-13.mes +++ b/module/srfi/srfi-13.mes @@ -66,11 +66,11 @@ (define (string-index s pred . rest) (let* ((start (and (pair? rest) (car rest))) - (end (and start (pair? (cdr rest)) (cadr rest)))) - (if (not (char? pred)) (error "string-index: not supported: pred=" pred)) + (end (and start (pair? (cdr rest)) (cadr rest))) + (pred (if (char? pred) (lambda (c) (eq? c pred)) pred))) (if start (error "string-index: not supported: start=" start)) (if end (error "string-index: not supported: end=" end)) (let loop ((lst (string->list s)) (i 0)) (if (null? lst) #f - (if (eq? (car lst) pred) i + (if (pred (car lst)) i (loop (cdr lst) (1+ i)))))))