|
|
|
|
|
by nine_k
1534 days ago
|
|
I'd say that Ruby has symbols because Ruby has mutable strings. If your strings are immutable and interned, they are as good as symbols; this is why Python does not have symbols. ECMASript introduced symbols because JavaScript strings, while immutable, are not necessarily interned. Symbols are much cheaper to compare for equality: you only need to compare the pointers / ids, not actual string bytes. Lisp has symbols for the same reason: Lisp strings are vectors, which are also mutable. |
|
Since Lisp symbols serve a central role as identifiers and structured objects, they are not like what Ruby uses. Lisp uses symbols also for named interned things, but that is only one purpose.
In Common Lisp symbols have a name, a value, a function, a package and a property list (a list of keys and their values). By default in a call like (mult 1 2 3), the global function will be retrieved from the symbol and the function will be called with the arguments. The property list sometimes will be used by an IDE to store information about the symbol: like where it was defined, what its definition is and similar.