diff options
author | Taylan Kammer <taylan.kammer@gmail.com> | 2021-05-12 22:36:26 +0200 |
---|---|---|
committer | Daniel Llorens <lloda@sarc.name> | 2023-09-29 15:28:20 +0200 |
commit | 3243d96bb5b9658f08847a7073fe6c0b2ccab6be (patch) | |
tree | 093111732f554ab5098bd2f9c4af922279fcc90f /module | |
parent | 1e3b5390e3c24e66013118e9751db4de5025a4a2 (diff) | |
download | guile-3243d96bb5b9658f08847a7073fe6c0b2ccab6be.tar.gz |
Fix (scheme base) string-for-each.
* module/scheme/base.scm (r7:string-for-each): New procedure.
Fixes <https://bugs.gnu.org/40584>.
Diffstat (limited to 'module')
-rw-r--r-- | module/scheme/base.scm | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/module/scheme/base.scm b/module/scheme/base.scm index b3d37a6ef..9ad16a371 100644 --- a/module/scheme/base.scm +++ b/module/scheme/base.scm @@ -51,6 +51,7 @@ open-output-bytevector get-output-bytevector peek-u8 read-u8 read-bytevector read-bytevector! read-string read-line + (r7:string-for-each . string-for-each) write-u8 write-bytevector write-string flush-output-port (r7:string-map . string-map) bytevector bytevector-append @@ -106,7 +107,7 @@ real? remainder reverse round set! set-car! set-cdr! string string->list string->number string->symbol string-append - string-copy string-copy! string-fill! string-for-each + string-copy string-copy! string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? syntax-error syntax-rules truncate @@ -401,7 +402,28 @@ (define (r7:string-map proc s . s*) (if (null? s*) (string-map proc s) - (list->string (apply map proc (string->list s) (map string->list s*))))) + (list->string (apply map proc (string->list s) (map string->list + s*))))) + +(define r7:string-for-each + (case-lambda + ((proc s) (string-for-each proc s)) + ((proc s1 s2) + (let ((len (min (string-length s1) + (string-length s2)))) + (let loop ((i 0)) + (when (< i len) + (proc (string-ref s1 i) + (string-ref s2 i)) + (loop (+ i 1)))))) + ((proc . strings) + (let ((len (apply min (map string-length strings)))) + (let loop ((i 0)) + (when (< i len) + (apply proc (map (lambda (s) + (string-ref s i)) + strings)) + (loop (+ i 1)))))))) (define (bytevector . lis) (u8-list->bytevector lis)) |