Symbols are immutable strings which can be compared for equality in constant time by comparing the pointers.
A symbol literal can be created by prefixing either an id or literal string with a '#'. Currently (9.5), putting parenthesis around symbol literals that are not otherwise in parenthesis (e.g., when being used in an 'if', or passed to a function/method, etc.) is recommended to preserve automatic tabbing levels in Emacs, since otherwise C-Mode will believe them to indicate a start of a preprocessor directive/macro.
symbol sym = (#abc123); symbol pkg = (#"symbol.with.chars.not.allowed.for.an.id"); if (sym == #abc) ...
To get the string component of a symbol, cast it to a str
instead of using toS(). This is because toS() functions/methods are providing identifying information, primarily for debugging, and thus for symbols includes the '#' in order to differentiate it from a string.
Comments
0 comments
Please sign in to leave a comment.