string->symbol(3scm)
β¨ 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 π¦
symbol->string(3scm)β the reverse girly π
β 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms