Node: Symbols, Next: , Previous: Pairs and lists, Up: Standard Procedures



Symbols

The STKLOS reader can read symbols whose names contain special characters or letters in the non standard case. When a symbol is read, the parts enclosed in bars ("|") will be entered verbatim into the symbol's name. The "|" characters are not part of the symbol; they only serve to delimit the sequence of characters that must be entered "as is". In order to maintain read-write invariance, symbols containing such sequences of special characters will be written between a pair of "|".

     '|a|                  =>  a
     (string->symbol "a")  =>  |A|
     (symbol->string '|A|) =>  "A"
     '|a  b|               =>  |a  b|
     'a|B|c                =>  |aBc|
     (write '|FoO|)        -| |FoO|
     (display '|FoO|)      -| FoO
     

symbol? obj R5RS
Returns #t if obj is a symbol, otherwise returns #f.
             (symbol? 'foo)          =>  #t
             (symbol? (car '(a b)))  =>  #t
             (symbol? "bar")         =>  #f
             (symbol? 'nil)          =>  #t
             (symbol? '())           =>  #f
             (symbol? #f)            =>  #f
             (symbol? :key)          =>  #f
          

symbol->string string R5RS
Returns the name of symbol as a string. If the symbol was part of an object returned as the value of a literal expression or by a call to the read procedure, and its name contains alphabetic characters, then the string returned will contain characters in the implementation's preferred standard case - STKLOS prefers lower case. If the symbol was returned by string->symbol, the case of characters in the string returned will be the same as the case in the string that was passed to string->symbol. It is an error to apply mutation procedures like string-set! to strings returned by this procedure.
             (symbol->string 'flying-fish)  =>  "flying-fish"
             (symbol->string 'Martin)       =>  "martin"
             (symbol->string (string->symbol "Malvina"))
                                            =>  "Malvina"
          

string->symbol string R5RS
Returns the symbol whose name is string. This procedure can create symbols with names containing special characters or letters in the non-standard case, but it is usually a bad idea to create such symbols because in some implementations of Scheme they cannot be read as themselves.
             (eq? 'mISSISSIppi 'mississippi)     =>  #t
             (string->symbol "mISSISSIppi")      =>  |mISSISSIppi|
             (eq? 'bitBlt (string->symbol "bitBlt"))
                                                 =>  #f
             (eq? 'JollyWog
                  (string->symbol
                    (symbol->string 'JollyWog))) =>  #t
             (string=? "K. Harper, M.D."
                       (symbol->string
                         (string->symbol "K. Harper, M.D.")))
                                                 =>  #t
          

string->unterned-symbol string STKLOS Procedure
Returns the symbol whose print name is made from the characters of string. This symbol is guaranteed to be unique (i.e. not eq? to any other symbol):
          (let ((ua (string->uninterned-symbol "a")))
            (list (eq? 'a ua)
                  (eqv? 'a ua)
                  (eq? ua (string->uninterned-symbol "a"))
                  (eqv? ua (string->uninterned-symbol "a"))))
                    => (#f #t #f #t)
          

gensym STKLOS Procedure
gensym prefix STKLOS Procedure
Creates a new symbol. The print name of the generated symbol consists of a prefix (which defaults to G) followed by the decimal representation of a number. If prefix is specified, it must be either a string or a symbol.
          (gensym)        => |G100|
          (gensym "foo-") => foo-101
          (gensym 'foo)   => foo-102