diff --git a/module/mes/scm.mes b/module/mes/scm.mes index 646c95ab..f8c19924 100644 --- a/module/mes/scm.mes +++ b/module/mes/scm.mes @@ -194,6 +194,12 @@ (define (string-ref s k) (list-ref (string->list s) k)) +(define (substring s start . rest) + (let* ((end (and (pair? rest) (car rest))) + (lst (list-tail (string->list s) start))) + (list->string (if (not end) lst + (list-head lst (- end start)))))) + (define (string-prefix? prefix string) (and (>= (string-length string) (string-length prefix)) diff --git a/string.c b/string.c index 9b489373..674e53b4 100644 --- a/string.c +++ b/string.c @@ -18,30 +18,6 @@ * along with Mes. If not, see . */ -SCM -substring (SCM x) ///((arity . n)) -{ - assert (TYPE (x) == PAIR); - assert (TYPE (car (x)) == STRING); - SCM s = STRING (car (x)); - assert (TYPE (cadr (x)) == NUMBER); - int start = VALUE (cadr (x)); - int end = VALUE (length (s)); - if (TYPE (cddr (x)) == PAIR) { - assert (TYPE (caddr (x)) == NUMBER); - assert (VALUE (caddr (x)) <= end); - end = VALUE (caddr (x)); - } - int n = end - start; - while (start--) s = cdr (s); - SCM p = cell_nil; - while (n-- && s != cell_nil) { - p = append2 (p, cons (MAKE_CHAR (VALUE (car (s))), cell_nil)); - s = cdr (s); - } - return MAKE_STRING (p); -} - SCM number_to_string (SCM x) {