A
list is any sequences of objects, such as symbols, numbers, or other lists,
enclosed by parenthesis. Much of the power and beauty of Lisp
is derived from the fact that even a program is because even functions
and programs are themselves lists.
Something
that is not a list may be generally classified as either a self-evaluating
form or a symbol. A self-evaluating form is a form, such as a number,
which evaluates to itself. A symbol is a variable which has
an associated value.
The
single quote in front of a list is an abbreviation for the function quote,
which returns its argument identically. For example (where
user input is blue, interpreter response underneath is black, and
comments are red):
> (quote 45)
45
> (quote "testing quote")
"testing quote"
> '(+ 1 2 3 (/ 4 5))) ;;
it does not evaluate the arithematic operations
(+ 1 2 3 (/ 4 5))
> '(a4 b4 c4)
;; Lisp is case-insensitive. It converts
all symbols to upper case.
(A4 B4 C4)
The
function setf sets the named variable to the value of the object
that follows.
> (setf zebra '(stripes white black))
(STRIPES WHITE BLACK)
>zebra
(STRIPES WHITE BLACK)
>(setf sum (+ 8
9 10))
27
;; note that performing an operation using sum
does not change the value of sum.
> (+ sum
10)
37
> sum
27
;; to destructively add 10 to the value stored
in sum, you would have to type:
> (setf sum (+ sum 10))
37
;; you can assign multiple values using setf by
listing pairs of variable names and values:
> (setf variable1 'value1
variable2 'value2 variable3 'value3)
;; it prints the last value assigned
VALUE3
> variable2
VALUE2