Next: , Previous: , Up: Data Types   [Contents][Index]


5.3.2 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 numbers, strings, symbols, cons cells (or lists) and vectors, all others have to be created by calling functions.

Single line comments are introduced by a 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. Block comments are also supported, introduced by the string ‘#|’ and terminated by ‘|#’. See 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 summary of how to write each type.

Numbers

A number is number written as an integer—decimal, octal (when the number is preceded by ‘#o’) or hexadecimal (when the number is preceded by ‘#x’)—or a decimal rational or floating point value. An optional minus sign may be the first character in a number. Some examples are,

42
    ⇒ 42

#o177
    ⇒ 127

#x-ff
    ⇒ -255

3/2
    ⇒ 3/2

1.23
    ⇒ 1.23

For full documentation, read See Number Read Syntax.

Strings

The read syntax of a string is simply the string with a double-quote character (‘"’) at each end, for more details see Strings.

"This is a string"
Character

In Librep, a character is an unsigend 8-bit integer. It read syntax is a question mark(‘?’) and the character itself. For the details, see See Characters.

?a
    ⇒ 97
Cons cells

A cons cell is written in what is known as dotted pair notation, an opening left-parenthesis, followed by the read syntax of the first object, followed by a dot, then the second object, and finally a closing right-parenthesis. For example:

("car" . "cdr")
Lists

The syntax of a list is similar to a cons cell, but the dot is removed and zero or more objects may be written:

(0 1 2 3)

("foo" ("bar" "baz") 100)

The second example is a list of three elements, a string, an inner list and a number.

Vectors

The read syntax of a vector is similar to that of a list, but with square brackets instead of parentheses,

[0 1 2 3]
Symbols

The read syntax of a symbol is its name, for example the read syntax of the symbol called ‘my-symbol’ is,

my-symbol

For more, read See Symbol Syntax.


Next: , Previous: , Up: Data Types   [Contents][Index]