diff --git a/ChangeLog.markdown b/ChangeLog.markdown index 57ecbd93..6fda46ec 100644 --- a/ChangeLog.markdown +++ b/ChangeLog.markdown @@ -9,6 +9,7 @@ New Features: Bug Fixes: - Fixed `rational?` to properly handle floating-point numbers. +- Migrated `string-fill!` from a macro to a function. This makes it easier to redefine, for example per SRFI 13. v3.19.1 -------- diff --git a/lib/core.scm b/lib/core.scm index 880949ea..48fa332c 100644 --- a/lib/core.scm +++ b/lib/core.scm @@ -331,11 +331,17 @@ ; End delayed evaluation section ; String Section -(define-syntax string-fill! - (syntax-rules () - ((_ _str _chr) - (set! _str - (make-string (string-length _str) _chr))))) +(define (string-fill! str fill . opts) + (letrec* ((len (string-length str)) + (start (if (> (length opts) 0) (car opts) 0)) + (end (if (> (length opts) 1) (cadr opts) len)) + (loop (lambda (i) + (cond + ((= i end) str) + (else + (string-set! str i fill) + (loop (+ i 1))))))) + (loop start))) (define (string-concatenate l) (apply string-append l))