string->symbol(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

✨ string->symbol β€” it's giving string-to-symbol conversion, bestie ✨

Okay so this is a page from the Scheme Programmer's Manual, manual page string->symbol(3scm), and honestly? It's a little icon and you're gonna love her. πŸ’–

🌸 LIBRARY 🌸

Import it from whichever flavor of Scheme you're living in, no judgment:

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

πŸ¦‹ SYNOPSIS πŸ¦‹

(string->symbol string)

πŸ’… DESCRIPTION πŸ’…

Bestie. It returns the symbol whose name is string. That's it. That's the whole vibe. ✨

But listen β€” and this is the tea β€” this procedure can create symbols that cannot be read back with read(3scm) after being written with write(3scm). Like, they exist, they're valid, but the round trip? Not happening. 😭

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 || β€” cute little empty bars, she ate.)

πŸŽ€ RETURN VALUES πŸŽ€

Returns a single value; a symbol. One and done. 🫢

🌈 EXAMPLES 🌈

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. (iykyk 😌)

(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

See how 'mISSISSIppi and 'mississippi are literally not the same symbol? Case matters, bestie. Highkey slay. πŸ”₯

πŸ‘‘ COMPATIBILITY πŸ‘‘

This procedure is in all Scheme reports starting with R2RS. She's been around. She's a legend. Periodt.

πŸ’€ 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. Not me saying "fail catastrophically" πŸ’€ β€” that's literally the spec's words. So like, don't test her.

πŸ¦‹ SEE ALSO πŸ¦‹

⭐ STANDARDS ⭐

R4RS, IEEE Scheme, R5RS, R6RS, R7RS. All of them. She's certified. πŸŽ€

πŸ“ HISTORY πŸ“

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. So she's got ancestors. Lineage. Main character energy from way back. πŸ‘‘

🧚 AUTHORS 🧚

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/. Go say hi! 🫢

πŸ™ˆ BUGS πŸ™ˆ

There are implementations that do not garbage collect the symbol interning table. So your symbols just... stay. Forever. Living in there rent-free. 😭 lowkey haunting tbh


And that's the page, bestie!! ✨ Handed to you straight from the 2022-05-13 edition of the scheme-manpages universe β€” go forth and intern some symbols responsibly πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from