string-map(3scm) Scheme Programmer's Manual string-map(3scm)

string-map - map a procedure over the characters in strings

(import (scheme base))              ;R7RS

(string-map proc string1 string2 ...)

The string-map procedure applies proc element-wise to the elements of the strings and returns a string of the results, in order.

If more than one string is given and not all strings have the same length, string-map terminates when the shortest string runs out.

The dynamic order in which proc is applied to the elements of the strings is unspecified.

If multiple returns occur from string-map, the values returned by earlier returns are not mutated.

Returns a single string object.

(string-map char-foldcase "AbdEgH")
        => "abdegh"
(string-map
 (lambda (c)
   (integer->char (+ 1 (char->integer c))))
 "HAL")
        => "IBM"
; Demonstrates how it ends on the shortest string
(string-map
 (lambda (c k)
   ((if (eqv? k #) char-upcase char-downcase)
    c))
 "studlycaps xxx"
 "ululululul")
        => "StUdLyCaPs"

It is an error if proc does not accept as many arguments as there are strings or does not return a single character. It is likewise an error if there are fewer than two arguments or if one of the arguments is outside its domain. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

It is also an error for proc to return a character which the implementation does not support. 7-bit ASCII (except #\null) must be supported. Any other character is optional and potentially an error (as described above). You can use the full-unicode feature identifier in cond-expand(3scm) to check if all of Unicode 6.0 is supported.

map(3scm)

R7RS

This procedure also appears in SRFI-13.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2022-03-29