--- srfi-118-2015-02-15.html 2015-02-15 07:56:46.131606612 -0800 +++ srfi-118.html 2015-04-19 21:42:31.457553138 -0700 @@ -20,7 +20,7 @@
string-append!
and
string-replace!
which allow the size of the string to change.
-We also require that standard Scheme procedures that return mutable strings
-(such as make-string
) return variable-size strings.
+We also require that the standard Scheme procedures make-string
+and string-copy
return variable-size strings.
@@ -131,7 +131,7 @@ appending each value (in order) to the end of string. A value can be a character or a string.
-The following example show to to process a string using
+The following example shows how to process a string using
string-for-each
and incrementally building
a result string
using string-append!
:
(define (translate-space-to-newline str) @@ -146,6 +146,8 @@ str) result))+
There is no requirement that this procedure execute in constant time, +even amortised (i.e. average) constant time.
Usage note: Compare with using string ports:
(define (translate-space-to-newline str) (let ((out (open-output-string))) @@ -166,7 +168,7 @@ but that depends on the strategy used bystring-append!
when the allocated buffer is too small. Thestring-append!
function is most useful when -using (reading) a string a interleaved with growing it, +using (reading) a string is interleaved with growing it, or when also usingstring-replace!
. @@ -196,6 +198,11 @@The implementation is trivial, assuming there is some indirection between the string object header and the actual stored characters. +Whenever the character buffer is full, it needs to be replaced with +a bigger buffer. If the size of the new buffer is a +fixed multiple of the size of the old buffer then +
string-append!
has amortized constant execution time. +(The multiple 1.5 seems a good choice.)If you have cheap Smalltalk-style
becomes:
(which is admittedly unlikely these days) then you can use that when you need to grow a string