| make-string(3scm) | Scheme Programmer's Manual | make-string(3scm) |
NAME
make-string - construct a string
LIBRARY
(import (rnrs)) ;R6RS (import (rnrs base)) ;R6RS (import (scheme r5rs)) ;R7RS (import (scheme base)) ;R7RS
SYNOPSIS
(make-string k) (make-string k char)
DESCRIPTION
Returns a newly allocated string of length k. If char is given, then all elements of the string are initialized to char, otherwise the contents of the string are unspecified.
RETURN VALUES
Returns a new string.
EXAMPLES
(make-string 3 #\a) => "aaa"
APPLICATION USAGE
This procedure can be a code smell because it is commonly used when programs construct strings using mutation. If characters are generated in sequential order then an alternative is to use open-string-output-port(3scm) or call-with-string-output-port(3scm). This additionally has the benefit that the length of the output does not need to be known ahead of time.
RATIONALE
This procedure is provided for programs that need to efficiently construct strings that are mutated in random order.
COMPATIBILITY
Implementations are allowed to have a unique zero-length string.
ERRORS
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its domain.
- R7RS
- The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.
- Unsupported characters (R7RS)
- It is an error to pass this procedure a character which the implementation does not support. 7-bit ASCII (except #\null) must be supported. Any other character is optional and potentially an error (as described above). You can use the full-unicode feature identifier in cond-expand(3scm) to check if all of Unicode 6.0 is supported.
SEE ALSO
call-with-string-output-port(3scm), list->string(3scm), vector->string(3scm)
STANDARDS
R2RS, R3RS, R4RS, IEEE Scheme, R5RS, R6RS, R7RS
HISTORY
This procedure appears in all Scheme reports since R2RS. Scheme before then (running on MACLISP) also had strings, but there does not appear to have been a constructor.
AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.
BUGS
Implementations vary in how well they handle a large k.
| 2026-07-22 |