make-string(3scm) Scheme Programmer's Manual make-string(3scm)

make-string - construct a string

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

(make-string k)
(make-string k char)

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.

Returns a new string.

(make-string 3 #\a)   =>  "aaa"

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.

This procedure is provided for programs that need to efficiently construct strings that are mutated in random order.

Implementations are allowed to have a unique zero-length string.

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.

call-with-string-output-port(3scm), list->string(3scm), vector->string(3scm)

R2RS, R3RS, R4RS, IEEE Scheme, R5RS, R6RS, R7RS

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.

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/.

Implementations vary in how well they handle a large k.
2026-07-22