diff --git a/module/srfi/srfi-13.mes b/module/srfi/srfi-13.mes index bf6a06e9..859e5160 100644 --- a/module/srfi/srfi-13.mes +++ b/module/srfi/srfi-13.mes @@ -54,14 +54,20 @@ (list (list->string (list-head lst (- (length lst) (length rest))))))))))) (define (string-take s n) - (list->string (list-head (string->list s) n))) + (cond ((zero? n) s) + ((> n 0) (list->string (list-head (string->list s) n))) + (else (error "string-take: not supported: n=" n)))) (define (string-drop s n) - (list->string (list-tail (string->list s) n))) + (cond ((zero? n) s) + ((> n 0) (list->string (list-tail (string->list s) n))) + (else s (error "string-drop: not supported: (n s)=" (cons n s))))) (define (string-drop-right s n) - (let ((length (string-length s))) - (list->string (list-head (string->list s) (- length n))))) + (cond ((zero? n) s) + ((> n 0) (let ((length (string-length s))) + (list->string (list-head (string->list s) (- length n))))) + (else (error "string-drop-right: not supported: n=" n)))) (define (string-delete pred s) (let ((p (if (procedure? pred) pred diff --git a/tests/srfi-13.test b/tests/srfi-13.test index 5fc9d689..1e6a9851 100755 --- a/tests/srfi-13.test +++ b/tests/srfi-13.test @@ -56,4 +56,10 @@ exit $? "f-o-o-:" (list->string (string-fold-right (lambda (e p) (cons e (cons #\- p))) '(#\:) "foo"))) +(pass-if-equal "string-drop" "bar" + (string-drop "foobar" 3)) + +(pass-if-equal "string-drop-right" "foo" + (string-drop-right "foobar" 3)) + (result 'report)