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


Read Syntax

As previously noted the Lisp reader translates textual descriptions of Lisp objects into the object they describe (source files are simply descriptions of objects). However, not all data types can be created in this way: in fact the only types which can are integers, strings, symbols, cons cells (or lists) and vectors, all others have to be created by calling functions.

Note that comments in a Lisp program are introduced by the semi-colon character (`;'). Whenever the Lisp reader encounters a semi-colon where it's looking for the read syntax of a new Lisp object it will discard the rest of the line of input. See section Comment Styles.

The read syntax of an object is the string which when given to the reader as input will produce the object. The read syntax of each type of object is documented in that type's main section of this manual but here is a small taste of how to write each type.

Integers
An integer is simply the number written in either decimal, octal (when the number is preceded by `0') or hexadecimal (when the number is preceded by `0x'). An optional minus sign may be the first character in a number. Some examples are,
42
    => 42

0177
    => 127

0xff
    => 255

-0x10
    => -16
Strings
The read syntax of a string is simply the string with a double-quote character (`"') at each end, for more details see section Strings.
"This is a string"
Cons cells
A cons cell is written in what is known as dotted pair notation and is just the two objects in the cell separated by a dot and the whole thing in parentheses,
(car . cdr)
Lists
The syntax of a list is similar to a cons cell (since this is what lists are made of): no dot is used and there may be zero or more objects,
(object1 object2 object3 ...)

("foo" ("bar" "baz") 100)
The second example is a list of three elements, a string, another list and a number.
Vectors
The read syntax of a vector is very similar to that of a list, simply use square brackets instead of parentheses,
[object1 object2 object3 ...]
Symbols
A symbol's read syntax is simply its name, for example the read syntax of a symbol called `my-symbol' is,
my-symbol


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