Previous chapter: Numbers

Dylan manual: Keywords and Symbols

15. Keywords and Symbols

Keywords and symbols are two very simple classes of object. The usefulness of keywords and symbols is that they are uniquely identifiable by name. Two keywords with the same name are guaranteed to be id?. Similarly, two symbols with the same name are guaranteed to be id?.

Keywords and symbols in Dylan are not case sensitive. That is, Foo and foo and FOO all indicate the same symbol. However, the case of keywords and symbols is remembered from the first time the keyword or symbol is entered. This case is used when the keyword or symbol is printed.

Symbols are used for creating named variables in Dylan. Keywords are not. The syntax of keywords includes a trailing colon. The colon is not part of the name of the keyword.

<symbol>	[Instantiable Clas[next citation]s]
<symbol> is a subclass of <object>.

<keyword>	[Instantiable Class]
<keyword> is a subclass of <object>.

as[next citation]   <symbol> string   ==>  symbol	[G.F. Method]
as   <keyword> string   ==>  keyword	[G.F. Method]
These methods on as return the keyword or symbol that has the name string. If the keyword or symbol does not yet exist, it is created. This method on as will always return the same keyword or symbol for strings of the same characters, without regard to character case.

? (as <symbol> "foo")
foo
? (id? 'FOO (as <symbol> "Foo"))
#t
? 'Foo
foo
? (as <keyword> "foo")
foo:
as   <string> symbol   ==>  string	[G.F. Method]
as   <string> keyword   ==>  string	[G.F. Method]
These methods on as return the name of the symbol or keyword, which will be a string. This string will contain the default character case of the symbol or keyword.

? (as <string> 'Foo)
"foo"
? (as <string> 'bar:)
"bar"

Next chapter: Characters