r7rs-small-texinfo

R7RS-small Scheme converted to Texinfo.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

symbols.texinfo (2726B)


      1 @node Symbols
      2 @section Symbols
      3 
      4 Symbols are objects whose usefulness rests on the fact that two symbols
      5 are identical (in the sense of @code{eqv?}) if and only if their names are
      6 spelled the same way. For instance, they can be used the way enumerated
      7 values are used in other languages.
      8 
      9 The rules for writing a symbol are exactly the same as the rules for
     10 writing an identifier; see @ref{Identifiers} and @ref{Lexical structure}.
     11 
     12 It is guaranteed that any symbol that has been returned as part of a
     13 literal expression, or read using the read procedure, and subsequently
     14 written out using the write procedure, will read back in as the identical
     15 symbol (in the sense of @code{eqv?}).
     16 
     17 Note: Some implementations have values known as ``uninterned symbols,''
     18 which defeat write/read invariance, and also violate the rule that two
     19 symbols are the same if and only if their names are spelled the same. This
     20 report does not specify the behavior of implementation-dependent
     21 extensions.
     22 
     23 @deffn procedure symbol? obj
     24 
     25 Returns @code{#t} if @var{obj} is a symbol, otherwise returns @code{#f}.
     26 
     27 @lisp
     28 (symbol? 'foo)         @result{} #t
     29 (symbol? (car '(a b))) @result{} #t
     30 (symbol? "bar")        @result{} #f
     31 (symbol? 'nil)         @result{} #t
     32 (symbol? '())          @result{} #f
     33 (symbol? #f)           @result{} #f
     34 @end lisp
     35 
     36 @end deffn
     37 
     38 @deffn procedure symbol=? @vari{symbol} @varii{symbol} @variii{symbol}@dots{}
     39 
     40 Returns @code{#t} if all the arguments all have the same names in the
     41 sense of @code{string=?}.
     42 
     43 Note: The definition above assumes that none of the arguments are
     44 uninterned symbols.
     45 
     46 @end deffn
     47 
     48 @deffn procedure symbol->string symbol
     49 
     50 Returns the name of @var{symbol} as a string, but without adding
     51 escapes. It is an error to apply mutation procedures like
     52 @code{string-set!} to strings returned by this procedure.
     53 
     54 @lisp
     55 (symbol->string 'flying-fish) @result{} "flying-fish"
     56 (symbol->string 'Martin)      @result{} "Martin"
     57 (symbol->string
     58  (string->symbol "Malvina"))
     59                               @result{} "Malvina"
     60 @end lisp
     61 
     62 @end deffn
     63 
     64 @deffn procedure string->symbol string
     65 
     66 Returns the symbol whose name is @var{string}. This procedure can
     67 create symbols with names containing special characters that would
     68 require escaping when written, but does not interpret escapes in its
     69 input.
     70 
     71 @lisp
     72 (string->symbol "mISSISSIppi")      @result{} mISSISSIppi
     73 (eqv? 'bitBlt
     74       (string->symbol "bitBlt"))    @result{} #t
     75 (eqv? 'LollyPop
     76      (string->symbol
     77        (symbol->string 'LollyPop)))
     78                                     @result{} #t
     79 (string=? "K. Harper, M.D."
     80           (symbol->string
     81             (string->symbol "K. Harper, M.D.")))
     82                                     @result{} #t
     83 @end lisp
     84 @end deffn