► |  | Reference: PLT Scheme

1 | Language Model
2 | Syntactic Forms
3 | Datatypes
4 | Structures
5 | Classes and Objects
6 | Units
7 | Contracts
8 | Pattern Matching
9 | Control Flow
10 | Concurrency
11 | Macros
12 | Input and Output
13 | Reflection and Security
14 | Operating System
15 | Memory Management
16 | Running PLT Scheme
| Bibliography
| Index

▼ | 3 | Datatypes

3.1 | Booleans and Equality
3.2 | Numbers
3.3 | Strings
3.4 | Byte Strings
3.5 | Characters
3.6 | Symbols
3.7 | Regular Expressions
3.8 | Keywords
3.9 | Pairs and Lists
3.10 | Mutable Pairs and Lists
3.11 | Vectors
3.12 | Boxes
3.13 | Hash Tables
3.14 | Sequences
3.15 | Dictionaries
3.16 | Procedures
3.17 | Void and Undefined

On this page:

symbol?
symbol->string
string->symbol
string->uninterned-symbol
gensym

Version: 4.1.4
top← prev up next →

#### 3.6`` Symbols

Symbols in Guide: PLT Scheme introduces symbols.

A symbol is like an immutable string, but symbols are normally interned, so that two symbols with the same character content are normally eq?. All symbols produced by the default reader (see Reading Symbols) are interned.

The two procedures string->uninterned-symbol and gensym generate uninterned symbols, i.e., symbols that are not eq?, eqv?, or equal? to any other symbol, although they may print the same as other symbols.

Regular (interned) symbols are only weakly held by the internal symbol table. This weakness can never affect the result of an eq?, eqv?, or equal? test, but a symbol may disappear when placed into a weak box (see Weak Boxes) used as the key in a weak hash table (see Hash Tables), or used as an ephemeron key (see Ephemerons).

(symbol? v) → boolean?
v : any/c

Returns #t if v is a symbol, #f otherwise.

Examples:
> (symbol? 'Apple)
#t
> (symbol? 10)
#f

(symbol->string sym) → symbol?
sym : symbol?

Returns a freshly allocated mutable string whose characters are the same as in sym.

Examples:
> (symbol->string 'Apple)
"Apple"

(string->symbol str) → symbol?
str : string?

Returns an interned symbol whose characters are the same as in str.

Examples:
> (string->symbol "Apple")
Apple
> (string->symbol "1")
|1|

(string->uninterned-symbol str) → symbol?
str : string?

Like (string->symbol str), but the resulting symbol is a new uninterned symbol. Calling string->uninterned-symbol twice with the same str returns two distinct symbols.

Examples:
> (string->uninterned-symbol "Apple")
Apple
> (eq? 'a (string->uninterned-symbol "a"))
#f

(gensym [base]) → symbol?
base : (or/c string? symbol?) = "g"

Returns a new uninterned symbol with an automatically-generated name. The optional base argument is a prefix symbol or string.

Examples:
> (gensym "apple")
apple190413

top← prev up next →