#REDIRECT [[Reserved word]]
{{Refimprove|date=December 2009}}
In [[computer programming]], a '''keyword''' is a [[word]] or [[identifier]] that has a particular meaning to the [[programming language]]. The meaning of keywords — and, indeed, the meaning of the notion of ''keyword'' — differs widely from language to language.
In many languages, such as [[C (programming language)|C]] and similar environments like [[C++]], a ''keyword'' is a [[reserved word]] which identifies a syntactic form. Words used in [[control flow]] constructs, such as <tt>if</tt>, <code>then</code>, and <code>else</code> are keywords. In these languages, keywords cannot also be used as the names of variables or functions.
In some languages, such as [[ALGOL]] and [[ALGOL 68|Algol 68]], keywords cannot be written verbatim, but must be [[Stropping (syntax)|stropped]]. This means that keywords must be marked somehow. E.g. by quoting them or by prefixing them by a special character.
Some languages, such as [[PostScript]], are extremely liberal in this approach, allowing core keywords to be redefined for specific purposes.
In [[Common Lisp]], the term "keyword" (or "keyword symbol") is used for a special sort of [[symbol (Lisp)|symbol]], or identifier. Unlike other symbols, which usually stand for variables or functions, keywords are self-[[Lisp (programming language)#Self-evaluating forms and quoting|quoting]] and self-evaluating<ref>[[Peter Norvig]]: ''Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp'', Morgan Kaufmann, 1991, ISBN 1-55860-191-0, [http://norvig.com/paip.html Web]</ref><sup>:98</sup> and are [[String interning|interned]] in the <tt>KEYWORD</tt> package.<ref>[http://www.lispworks.com/documentation/HyperSpec/Body/t_kwd.htm#keyword ''Type'' '''KEYWORD'''] from the [[Common Lisp HyperSpec]]</ref> Keywords are usually used to label named arguments to functions, and to represent symbolic values.
Languages vary as to what is provided as a keyword and what is a [[library routine]]. Some languages, for instance, provide keywords for input/output operations whereas in others these are library routines. In [[Python (programming language)|Python]] (versions earlier than 3.0) and many [[BASIC]] dialects, <code>print</code> is a keyword. In contrast, the C and Lisp equivalents <code>printf</code> and <code>format</code> are functions in the standard library.
Typically, when a programmer attempts to use a keyword for a variable or function name, a compilation error will be triggered. In most modern editors, the keywords are automatically set to have a particular text colour to remind or inform the programmers that they are keywords.
In languages with [[macro (computer science)|macros]] or [[lazy evaluation]], control flow constructs such as <code>if</code> can be implemented as macros or functions. In languages without these expressive features, they are generally keywords.
==See also==
* [[List of Java keywords]]
* [[Symbol (programming)]]
==References==
<references/>
[[Category:Programming constructs]] ▼
[[Category:Programming language topics]]
▲[[Category:Programming constructs]]
{{Prog-lang-stub}}
[[cs:Klíčové slovo]]
[[da:Nøgleord (programmering)]]
[[de:Schlüsselwort (Programmierung)]]
[[es:Palabra clave]]
[[fa:واژه کلیدی]]
[[it:Parole chiave]]
[[hu:Kulcsszó]]
[[pa:ਕੀਵਰਡ (ਕੰਪਿਊਟਿੰਗ)]]
[[pl:Słowo kluczowe (informatyka)]]
[[pt:Palavra chave]]
[[sq:Fjala kyçe (programim)]]
[[th:คำหลัก (การเขียนโปรแกรม)]]
|