1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
\chapter{Mutable strings}
\label{stringmutationchapter}
The {\cf string-set!} procedure provided by the \defrsixlibrary{mutable-strings}
library allows mutating the characters of a string in-place.
\begin{entry}{%
\proto{string-set!}{ string k char}{procedure}}
\domain{%\var{string} must be a string,
\vr{K} must be a valid index of \var{string}%, and \var{char} must be a character
.}
The {\cf string-set!} procedure stores \var{char} in element \vr{k} of \var{string}
and returns \unspecifiedreturn. % <!>
Passing an immutable string to {\cf string-set!} should cause an exception
with condition type {\cf\&assertion} to be raised.
\begin{scheme}
(define (f) (make-string 3 \sharpsign\backwhack{}*))
(define (g) "***")
(string-set! (f) 0 \sharpsign\backwhack{}?) \ev \theunspecified
(string-set! (g) 0 \sharpsign\backwhack{}?) \ev \unspecified
; \textrm{should raise \exception{\&assertion}}
(string-set! (symbol->string 'immutable)
0
\sharpsign\backwhack{}?) \ev \unspecified
; \textrm{should raise \exception{\&assertion}}%
\end{scheme}
\begin{note}
Implementors should make {\cf string-set!} run in constant
time.
\end{note}
\end{entry}
\begin{entry}{%
\proto{string-fill!}{ string char}{procedure}}
Stores \var{char} in every element of the given \var{string} and returns \unspecifiedreturn. % <!>
\end{entry}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "r6rs-lib"
%%% End:
|