Lisp reader: Difference between revisions

Content deleted Content added
new
 
 
(11 intermediate revisions by 8 users not shown)
Line 1:
In the programming language [[Lisp (programming language)|Lisp]], the '''reader''' or '''<code>read</code> function''' is the [[parser]] which converts the textual form of Lisp objects to the corresponding internal object structure.
 
In the original Lisp, S-expressions consisted only of [[symbol (programming)|symbol]]s, integers, and the list constructors <code>( <i>''x<sub>i</sub>...</i>'' )</code> and <code>(<i>''x</i>'' . <i>''y</i>'')</code>. Later Lisps, culminating in [[Common Lisp]], added literals for floating-point, complex, and rational numbers, strings, and constructors for vectors.
 
The reader is responsible for parsing list structure, [[String interning|interning]] symbols, converting numbers to internal form, and calling read macros.
 
==Read table==
Line 7 ⟶ 9:
The reader is controlled by the <code>readtable</code>, which defines the meaning of each [[character (computing)|character]].
 
==Read macros=={{anchor|Read macros}}==
 
Unlike most programming languages, Lisp supports parse-time execution of programs, called "read macros" or "reader macros". These are used to extend the syntax either in universal or program-specific ways. For example, the [[Lisp_Lisp (programming_languageprogramming language)#Self-evaluating_forms_and_quotingevaluating forms and quoting|quoted form]] <code>(quote <i>''x</i>'')</code> operator can be abbreviated as <code>{{'}}''<i>x</i>''</code>. The <code>'</code> operator couldcan be defined as a read macro which reads the following list and wraps it with <code>quote</code>. Similarly, the [[Lisp (programming language)#Backquote|backquote operator]] (` ) can be defined as a read macro.
 
==NotesReferences==
{{Reflist}}
<references/>
 
==Bibliography==
 
* [[John McCarthy (computer scientist)|John McCarthy]] ''et al.'', ''LISP 1.5 Programmer's Manual'', MIT Press, 1962.
* [[David Moon|David A. Moon]], ''MACLISP Reference Manual'', 1974.
* [[Guy Steele]], ''Common LISP: The Language'', Second Edition, 1990.
 
[[Category:Lisp (programming language)]]
[[Category:ParsersParsing]]
{{programming-stub}}