[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

string->symbol, symbol->string



"symbol->string" and "string->symbol functions are not analogous to
"list->string" or "string->list".

"list->string" converts the same data from one representation into
another, with no loss of information.  The same is true for "string->list",
"list->vector", "vector->list" and "character->integer".  

A symbol is more than just an alternate representation for a string.
It can be an identifier or keyword.  Some implementations allow symbols
to have property lists.  All of this information is lost in the conversion
from symbol to string, some is regained in the opposite conversion.
I tend to think of the name of a symbol as an attribute of that symbol.
"symbol->string" is more correctly called "symbol-name".

Furthermore, whereas one can expect "string->list" to return a new list
made up of unique cons-cells, "string->symbol" may return an existing
symbol.  The name "intern" is more appropriate for this functionality.
(Perhaps "hash-make-symbol" would be a better name.)

If making a unique, uninterned symbol is supported, the name "make-symbol"
is appropriate.  

If what we are really doing when we say "make-symbol" or "string->symbol"
was changing representations, then "string->symbol" would be fine.  But
it isn't a type conversion we are doing, it's symbol creation (or lookup).
It seems analogous to saying "make-vector" should be called "integer->vector"
because we are taking an integer, n, and returning a vector of length n.
The name is only one aspect of a symbol in much the same way that the length
is only one aspect of a vector.

        Kent Dybvig
        decvax!mcnc!unc!dyb
        dyb.unc@Csnet-Relay