Next: , Previous: , Up: strings   [Index]


25.7 Mapping functions

Function: string-map proc str0 str ...

Build and return a newly allocated string mapping proc over all the characters of the string arguments, from zero to the end in increasing order. It is an error if the strings have different length.

proc must return a character and it is applied to the elements as:

(proc idx
  (string-ref str0 idx)
  (string-ref str  idx)
  ...)

where idx is the current index.

Function: string-map! proc str0 str ...
Function: string-map*! proc str0 str ...

Mutate string str0 mapping proc over all the elements of the string arguments, from zero to the end in increasing order.

string-map! must be applied to strings of the same length; string-map*! accepts strings of different length and iterates until the end of the shorter is reached.

proc is applied to the elements as:

(proc idx
  (string-ref str0 idx)
  (string-ref str  idx)
  ...)

where idx is the current index.

Function: string-for-each* proc str0 str ...

Apply proc over all the elements of the string arguments, from zero to the end in increasing order. This function accepts strings of different length and iterates until the end of the shorter is reached.

proc is applied to the elements as:

(proc idx
  (string-ref str0 idx)
  (string-ref str  idx)
  ...)

where idx is the current index.

Mapping over substrings

Function: %substring-map proc str start past
Macro: substring-map proc S

Build and return a new string mapping proc over the characters in the selected substring of str, from index start to index past in increasing order. proc must be a char->char procedure.

Function: %substring-map! proc str start past
Macro: substring-map! proc S

Mutate the selected substring of str, mapping proc over its characters from index start to index past in increasing order. proc must be a char->char procedure.

Function: %substring-for-each proc str start past
Macro: substring-for-each proc S

Apply proc to each character in the selected substring of str, from index start to index past in increasing order.

Function: %substring-for-each-index proc str start past
Macro: substring-for-each-index proc S

Apply proc to each index in the selected substring of str, from index start to index past in increasing order. This is simply a method of looping over a string that is guaranteed to be safe and correct.


Next: , Previous: , Up: strings   [Index]