string->symbol(3scm) Scheme Programmer's Manual string->symbol(3scm)

string->symbol - string to symbol conversion

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

(string->symbol string)

Returns the symbol whose name is string.

This procedure can create symbols that cannot be read back with read(3scm) after being written with write(3scm). In R6RS implementations this happens when string is the empty string, because there is no lexical syntax for the symbol with the empty name. (In R7RS the empty symbol is written as ||).

Returns a single value; a symbol.

In the examples below the behavior would change if a case-folding reader was used. This may be enabled with the #!fold-case directive. In R6RS this directive appears in the non-normative appendix. In R5RS and earlier reports it was possible for case conversion, either to upper or lower case, to be enabled by default.

(eq? 'mISSISSIppi 'mississippi)
    => #f
(string->symbol "mISSISSIppi")
    => the symbol with name "mISSISSIppi"
(eq? 'bitBlt (string->symbol "bitBlt"))
    => #t
(eq? 'JollyWog
     (string->symbol
      (symbol->string 'JollyWog)))
    => #t
(string=? "K. Harper, M.D."
          (symbol->string
           (string->symbol "K. Harper, M.D.")))
    => #t

This procedure is in all Scheme reports starting with R2RS.

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.

symbol->string(3scm)

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

This procedure first appeared with this name in R2RS. Earlier Scheme running on MacLisp had the getpname procedure that returned an atomic symbol's print name as a character string.

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

There are implementations that do not garbage collect the symbol interning table.
2022-05-13