Node:SRFI-13 Fold/Unfold/Map, Next:, Previous:SRFI-13 Reverse/Append, Up:SRFI-13



39.11.12 Fold/Unfold/Map

string-map, string-for-each etc. are for iterating over the characters a string is composed of. The fold and unfold procedures are list iterators and constructors.

string-map proc s [start end] Scheme Procedure
proc is a char->char procedure, it is mapped over s. The order in which the procedure is applied to the string elements is not specified.

string-map! proc s [start end] Scheme Procedure
proc is a char->char procedure, it is mapped over s. The order in which the procedure is applied to the string elements is not specified. The string s is modified in-place, the return value is not specified.

string-fold kons knil s [start end] Scheme Procedure
string-fold-right kons knil s [start end] Scheme Procedure
Fold kons over the characters of s, with knil as the terminating element, from left to right (or right to left, for string-fold-right). kons must expect two arguments: The actual character and the last result of kons' application.

string-unfold p f g seed [base make_final] Scheme Procedure
string-unfold-right p f g seed [base make_final] Scheme Procedure
These are the fundamental string constructors.
  • g is used to generate a series of seed values from the initial seed: seed, (g seed), (g^2 seed), (g^3 seed), ...
  • p tells us when to stop - when it returns true when applied to one of these seed values.
  • f maps each seed value to the corresponding character in the result string. These chars are assembled into the string in a left-to-right (right-to-left) order.
  • base is the optional initial/leftmost (rightmost) portion of the constructed string; it default to the empty string.
  • make_final is applied to the terminal seed value (on which p returns true) to produce the final/rightmost (leftmost) portion of the constructed string. It defaults to (lambda (x) "").

string-for-each proc s [start end] Scheme Procedure
proc is mapped over s in left-to-right order. The return value is not specified.