146 lines
7.8 KiB
HTML
146 lines
7.8 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>1.2.7. Overview of Syntax</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Overview of Syntax">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html1654 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1652 HREF="node7.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1648 HREF="node13.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1656 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1657 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1655 HREF="node15.html"> Data Types</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1653 HREF="node7.html"> Notational Conventions</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1649 HREF="node13.html"> The Lisp Reader</A>
|
||
|
<HR> <P>
|
||
|
<H2><A NAME=SECTION00527000000000000000>1.2.7. Overview of Syntax</A></H2>
|
||
|
<P>
|
||
|
Certain characters are used in special ways in the syntax of Common Lisp.
|
||
|
The complete syntax is explained in detail in chapter <A HREF="node186.html#IO">22</A>,
|
||
|
but a quick summary here may be useful:
|
||
|
<DL COMPACT>
|
||
|
<DT><tt>(</tt>
|
||
|
<DD>
|
||
|
A left parenthesis begins a list of items. The list may
|
||
|
contain any number of items, including zero. Lists may be nested.
|
||
|
For example, <tt>(cons (car x) (cdr y))</tt> is a list of three things,
|
||
|
of which the last two are themselves lists.
|
||
|
<P>
|
||
|
<DT><tt>)</tt>
|
||
|
<DD> A right parenthesis ends a list of items.
|
||
|
<P>
|
||
|
<DT><tt>'</tt>
|
||
|
<DD> An acute accent (also called single
|
||
|
quote or apostrophe) followed by an expression <i>form</i>
|
||
|
is an abbreviation for <tt>(quote <i>form</i>)</tt>. Thus <tt>'foo</tt> means
|
||
|
<tt>(quote foo)</tt> and <tt>'(cons 'a 'b)</tt> means <tt>(quote (cons (quote a) (quote b)))</tt>.
|
||
|
<P>
|
||
|
<DT><tt>;</tt>
|
||
|
<DD> Semicolon is the comment character. It and all
|
||
|
characters up to the end of the line are discarded.
|
||
|
<P>
|
||
|
<DT><tt>"</tt>
|
||
|
<DD> Double quotes surround character strings: <BR><tt>"This is a thirty-nine-character string."</tt>
|
||
|
<P>
|
||
|
<DT><tt>\</tt>
|
||
|
<DD> Backslash is an escape character.
|
||
|
It causes the next character to be treated as a letter rather than for its usual
|
||
|
syntactic purpose. For example, <tt>A\(B</tt> denotes a symbol whose
|
||
|
name consists of the three characters <tt>A</tt>, <tt>(</tt>, and <tt>B</tt>. Similarly,
|
||
|
<tt>"\""</tt> denotes a character string containing one character, a
|
||
|
double quote, because the first and third double quotes serve to delimit the
|
||
|
string, and the second double quote serves as the contents of the string. The
|
||
|
backslash causes the second double quote to be taken literally and prevents it
|
||
|
from being interpreted as the terminating delimiter of the string.
|
||
|
<P>
|
||
|
<DT><tt>|</tt>
|
||
|
<DD> Vertical bars are used in pairs
|
||
|
to surround the name (or part of the name) of a symbol that has
|
||
|
many special characters in it. It is roughly equivalent to putting a
|
||
|
backslash in front of every character so surrounded. For example,
|
||
|
<tt>|A(B)|</tt>, <tt>A|(|B|)|</tt>, and <tt>A\(B\)</tt> all mean the symbol whose name
|
||
|
consists of the four characters <tt>A</tt>, <tt>(</tt>, <tt>B</tt>, and <tt>)</tt>.
|
||
|
<P>
|
||
|
<DT><tt>#</tt>
|
||
|
<DD> The number sign signals the beginning of a
|
||
|
complicated syntactic structure.
|
||
|
The next character designates the precise syntax to follow.
|
||
|
For example, <tt>#o105</tt> means <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40193.gif"> (105 in octal notation);
|
||
|
<tt>#x105</tt> means <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40195.gif"> (105 in hexadecimal notation);
|
||
|
<tt>#b1011</tt> means <IMG ALIGN=BOTTOM ALT="" SRC="_24769_tex2html_wrap40197.gif"> (1011 in binary notation);
|
||
|
<tt>#\L</tt> denotes a character object for the character <tt>L</tt>; and
|
||
|
<tt>#(a b c)</tt> denotes a vector of three elements <tt>a</tt>, <tt>b</tt>, and <tt>c</tt>.
|
||
|
A particularly important case is that <tt>#'<i>fn</i></tt> means <tt>(function <i>fn</i>)</tt>,
|
||
|
in a manner analogous to <tt>'<i>form</i></tt> meaning <tt>(quote <i>form</i>)</tt>.
|
||
|
<P>
|
||
|
<DT><tt>`</tt>
|
||
|
<DD> Grave accent (``backquote'') signals that
|
||
|
the next expression is a template that may contain commas. The backquote syntax
|
||
|
represents a program that will construct a data structure
|
||
|
according to the template.
|
||
|
<P>
|
||
|
<DT><tt>,</tt>
|
||
|
<DD> Commas are used within the backquote syntax.
|
||
|
<P>
|
||
|
<DT><tt>:</tt>
|
||
|
<DD> Colon is used to indicate which package a
|
||
|
symbol belongs to. For example, <tt>network:reset</tt> denotes the symbol named
|
||
|
<tt>reset</tt> in the package named <tt>network</tt>. A leading colon indicates a <i>keyword</i>, a symbol that always evaluates to itself.
|
||
|
The colon character is not actually part of the print name
|
||
|
of the symbol.
|
||
|
This is all explained in chapter <A HREF="node111.html#XPACK">11</A>; until you read
|
||
|
that, just keep in mind that a symbol notated with a leading colon
|
||
|
is in effect a constant that evaluates to itself.
|
||
|
<P>
|
||
|
</DL>
|
||
|
<P>
|
||
|
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
<i>Notice of correction.</i>
|
||
|
In the first edition, the characters ``<tt>,</tt>'' and ``<tt>:</tt>'' at the
|
||
|
left margin above were inadvertently omitted.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
|
||
|
<P>
|
||
|
Brackets, braces, question mark, and exclamation point
|
||
|
(that is, <tt>[</tt>, <tt>]</tt>, <tt>{</tt>, <tt>}</tt>,
|
||
|
<tt>?</tt>, and <tt>!</tt>) are not used for any purpose in standard Common Lisp syntax.
|
||
|
These characters are explicitly reserved to the user, primarily
|
||
|
for use as <i>macro characters</i> for user-defined lexical syntax extensions
|
||
|
(see section <A HREF="node190.html#MACROCHARACTERSSECTION">22.1.3</A>).
|
||
|
<P>
|
||
|
<img align=bottom alt="old_change_begin" src="gif/old_change_begin.gif"><br>
|
||
|
All code in this book is written using lowercase letters.
|
||
|
Common Lisp is generally insensitive to the case in which code
|
||
|
is written. Internally, names of symbols are ordinarily
|
||
|
converted to and stored in uppercase form.
|
||
|
There are ways to force case conversion on output if desired;
|
||
|
see <tt>*print-case*</tt>.
|
||
|
In this book, wherever an interactive exchange between a user
|
||
|
and the Lisp system is shown, the input is exhibited with lowercase
|
||
|
letters and the output with uppercase letters.
|
||
|
<br><img align=bottom alt="old_change_end" src="gif/old_change_end.gif">
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
X3J13 voted in June 1989 (READ-CASE-SENSITIVITY) <A NAME=380> </A> to introduce
|
||
|
<tt>readtable-case</tt>. Certain settings allow the names of symbols
|
||
|
to be case-sensitive. The default behavior, however, is as described
|
||
|
in the previous paragraph. In any event, only uppercase letters
|
||
|
appear in the internal print names of symbols naming the
|
||
|
standard Common Lisp facilities described in this book.
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
|
||
|
<BR> <HR><A NAME=tex2html1654 HREF="node15.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html1652 HREF="node7.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html1648 HREF="node13.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html1656 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html1657 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html1655 HREF="node15.html"> Data Types</A>
|
||
|
<B>Up:</B> <A NAME=tex2html1653 HREF="node7.html"> Notational Conventions</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html1649 HREF="node13.html"> The Lisp Reader</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|