chickadee » srfi-152 » string-map

string-map proc string₁ string₂ procedure

It is an error if proc does not accept as many arguments as the number of string arguments passed to string-map, does not accept characters as arguments, or returns a value that is not a character or string.

The string-map procedure applies proc element-wise to the characters of the string arguments, converts each value returned by proc to a string, and returns the concatenation of those strings. If more than one string argument is given and not all have the same length, then string-map terminates when the shortest string argument runs out. The dynamic order in which proc is called on the characters of the string arguments is unspecified, as is the dynamic order in which the coercions are performed. If any strings returned by proc are mutated after they have been returned and before the call to string-map has returned, then string-map returns a string with unspecified contents; the string-map procedure itself does not mutate those strings.

Compatibility note: This string-map is the one found in R7RS-small, and not the one from srfi-13 (which takes optional start/end indices rather than additional string arguments).

Example:

(string-map (lambda (c0 c1 c2)
               (case c0
                ((#\1) c1)
                ((#\2) (string c2))
                ((#\-) (string #\- c1))))
            "1222-1111-2222"
            "Hi There!"
            "Dear John")
     ⇒ "Hear-here!"