Previous section: Characters

Dylan reference manual -- Symbols


The <symbol> class provides a built-in, non-case-sensitive dictionary that associates a string with a unique immutable object that can be compared with == (which should be faster than calling a string-comparison routine). This dictionary is accessed through the as function: as(<symbol>, string) and as(<string>, symbol). Any string can be used, even ones that aren't allowed as variable names.

For symbols that use the same restricted character set that are allowed in variable names, the "keyword syntax" foo: (the symbol followed by ":") may be used everywhere that keywords are allowed in the grammar. The trailing colon is not part of the symbol.

? example: == #"Example"

The case of symbols is remembered from the first time the symbol is entered. as(<string>, symbol) returns the original case.

<symbol>	[Class]
<symbol> is a subclass of <object>.
as   <symbol> string   =>  symbol	[G.F. Method]
This method on as returns the symbol that has the name string. If the symbol does not yet exist, it is created. This method on as will always return the same symbol for strings of the same characters, without regard to alphabetic case.
? as (<symbol>, "foo")
? #"FOO" == as (<symbol>, "Foo")
? #"Foo"
as   <string> symbol   =>  string	[G.F. Method]
This method on as returns the name of the symbol, which will be a string.
? as (<string>, #"Foo")

Next section: 11. Numbers