Commits

Taylor Venable committed a7ad30c

Add new string functions

* string-append*
* string-map
* string-for-each
* string-fold

Comments (0)

Files changed (1)

       (vector-set! v i (string-ref s i)))
     v))
 
+(define (string-append* . args)
+  (apply string-append
+         (map (lambda (x) (or (and (char? x) (string x)) x))
+              args)))
+
+(define (string-map f s)
+  (let ((result (make-string (string-length s))))
+    (do ((i 0 (+ i 1)))
+        ((= i (string-length s)) result)
+      (string-set! result i (f (string-ref s i))))))
+
+(define (string-for-each f s)
+  (do ((i 0 (+ i 1)))
+      ((= i (string-length s)) s)
+    (f (string-ref s i))))
+
+(define (string-fold f init s)
+  (let loop ((result (string-copy init)) (i 0))
+    (if (= i (string-length s))
+      result
+      (loop (f result (string-ref s i)) (+ i 1)))))
+
 (define (vector->string v)
   (with-output-to-string '()
     (lambda ()
       (do ((i 0 (+ i 1)))
           ((= i (vector-length v)))
         (display (vector-ref v i))))))
+
+;; Local Variables:
+;; scheme-dialect: gambit
+;; End:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.