Most popular computer languages don't have symbols as a data type. You can make do with a string, or encode your symbol as a small integer or enum. It's a hack, but simple enough and common enough that it doesn't need a second thought.
Lisp has symbols, though, so if you are using a string as a stand-in you should give it a second thought. In Lisp, symbols and strings have different roles. Strings are composite objects, symbols are atomic. String operations are concerned with the contents of the string, symbol operations are concerned with the identity of the symbol.
I saw a Common Lisp Tic Tac Toe program that represented the
players' marks with the strings
"O". I could see no reason why it couldn't have
used the symbols
:O. Or how about the
Symbolic processing is the raison d'être of Lisp. It's a little absurd to represent symbols as strings in Lisp.
Absurd, or a TEACHABLE MOMENT? :)
In some Schemes/Lisps symbols aren't garbage collected while strings are, so leaving user input in the form of strings avoids the possibility of one type of DOS attack.
Post a Comment