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


5.18 Mutable strings

The string-set! procedure provided by the (rnrs mutable-strings (6)) library allows mutating the characters of a string in–place.

Procedure: string-set! string k char

k must be a valid index of string.

The string-set! procedure stores char in element k of string and returns unspecified values.

Passing an immutable string to string-set! should cause an exception with condition type &assertion to be raised.

(define (f) (make-string 3 #\*))
(define (g) "***")
(string-set! (f) 0 #\?)         ⇒ unspecified
(string-set! (g) 0 #\?)         ⇒ unspecified
                                ; should raise exception &assertion

(string-set! (symbol->string 'immutable)
             0
             #\?)               ⇒ unspecified
                                ; should raise exception &assertion

NOTE Implementors should make string-set! run in constant time.

Procedure: string-fill! string char

Store char in every element of the given string. As Vicare extension: the return value is string itself.