(make-array dimension-list) - returns an array with dimensions as specified by the list.
(aref array -numbers-) - returns the elements of the array referred to by interpreting
the numbers as subscripts. Examples:
>(setq foo (make-array '(4 2)
More readable macros:
Note that to write a macro you must anticipate what the target code will look like and
construct it in the macro body:
(defmacro nil! (x)
(list 'if (list '< x 0.0) (list 'setq x nil)
What a pain!
Instead of that, let's use backquotes
Basic predicates: (atom exp), (listp exp),
Numerical predicates: (evenp number), (oddp number), (zerop number)
(not exp) - returns t iff exp is nil
The following return t iff all the arguments comply with the specified predic
Streams are sources/sinks for I/O. Types of streams:
symbols (for string manipulation).
All the I/O functions may be applied to any stream.
where stream is a pathname;
(read) - reads in one s-expression
causes a "newline" to appear before the object it prints, and a space to follow
afterwards. It also returns its argument as its value.
is similar but without the newline or space).
Nameless Functions: LAMBDA
When using functions as arguments to other functions (e.g. apply) you sometimes
have to create little functions that are only used once (e.g. cubed).
Solution: create a function without a name, using the lambda notation.
The function function
When you supply a function as an argument to another function, so that the functions
needs to be quoted, use the special function function (or #').
Use function to quote named functions as well as lambda expressions.
Variations on do
What's wrong with the following code?
(defun squares (n)
(do (i 1 (1+ i)
(i2 (* i i) (* i i)
(> i n) nil)
(format t "~%i: ~d i^2: ~d" i i2)
do* - same as do except each index variable is assigned the value of
each initi or repi before the
A package has 2 kinds of symbols: internal and external.
Both are interned by read to the current package.
A symbol is made external using: export
my-package>(defun factorial (n)
(cond (zerop n) 1)
(t (* n (factorial (1- n)
You can use so
The Nature of LISP
Mainly used in Artificial Intelligence; prereq for AI subject
Functional (vs. procedural)
Flexibility; ease of prototyping
The History of LISP
John McCarthy (MIT) 1958
Second oldest language still in
How can we break down task into forms that involve smaller version of same
How to combine smaller versions to solve original problem?
When do we stop breaking down the task? (grounding condition)