Go to the first, previous, next, last section, table of contents.

Understanding Keywords

Smalltalk has a class UniqueString of strings, which guarantees that no two "distinct" (that is, having different memory addresses) UniqueStrings contain the same characters in the same order (that is, are equal in a visual, textual sense). UniqueStrings take longer to create than vanilla strings, but can be a useful efficiency hack in that they may be sorted, compared and looked up using fast integer operations on their addresses, rather than slow character-by-character comparisons of their contents.

The Lisp keyword serves a similar purpose: While there may be many symbols with a given name (albeit at most one per package), there can be at most one keyword with a given name. Keywords thus provide a Muq-global vocabulary of symbols which may be distinguished at a glance by humans and in a machine cycle by computers, useful as property names, object keys, as readable special values for variables, and in general anywhere that efficiently distinguishable names are handy.

Since keywords form a global resource and cannot easily be recycled once created, it is best to avoid creating large numbers of keywords: Use strings or uninterned symbols instead if you need temporary values.

Keywords are kept in the special package .lib.keyword. All keywords are constants, all are exported from the keyword package, and all keywords have themselves as their value (meaning that is is never necessary to explicitly quote them).

To make keywords syntactically more convenient, they are written `:xyzzy' rather than `keyword:xyzzy'. This is a special hardwired exception to the general symbol naming and printing rules.

The entire keyword package is a very special hardwired hack: You should never enter non-keyword symbols into it, unexport keyword symbols, or indeed directly do much of anything with it.

Keywords are normally created simply by mentioning them by name in code: :my-name or such.

Use keywords when you need an efficient vocabulary global to the database, efficiently usable without confusion from any package, independent of usePackage settings.

Go to the first, previous, next, last section, table of contents.