Next: , Previous: Modification of Strings, Up: Strings


6.10 Variable-Length Strings

MIT/GNU Scheme allows the length of a string to be dynamically adjusted in a limited way. When a new string is allocated, by whatever method, it has a specific length. At the time of allocation, it is also given a maximum length, which is guaranteed to be at least as large as the string's length. (Sometimes the maximum length will be slightly larger than the length, but it is a bad idea to count on this. Programs should assume that the maximum length is the same as the length at the time of the string's allocation.) After the string is allocated, the operation set-string-length! can be used to alter the string's length to any value between 0 and the string's maximum length, inclusive.

— procedure: string-maximum-length string

Returns the maximum length of string. The following is guaranteed:

          (<= (string-length string)
              (string-maximum-length string))     =>  #t
     

The maximum length of a string never changes.

— procedure: set-string-length! string k

Alters the length of string to be k, and returns an unspecified value. K must be less than or equal to the maximum length of string. set-string-length! does not change the maximum length of string.