CSC 319 Lecture 9:
Reading: Chassell 1-3, 7, 9, 11, 17. Sethi Chapters 10
Programming environment issues
Normally, you write Lisp code in a .el file, and load it into your Emacs
session by executing (load-file "file.el"). Many Emacs functions are
helpful in finding online documentation on Emacs Lisp, including
"apropos" and "describe-function". Invoke these interactively by
typing escape-X and then typing the function name and pressing return.
Some more Lisp functions
- (length L) gives the length of L.
- (null X) tells whether X is nil.
- (not X) tells whether X is not nil.
- (append L1 L2) produces a list with elements from L1 followed by L2.
- (apply f L) calls f with L as parameters.
- (mapcar f L) calls f repeatedly, using each element of L as parameters.
Lambda forms
(lambda (x) (* x x)) is an example of a lambda form. It is essentially
an anonymous function, usable anywhere a function name would be used.
Lisp Warmup Assignment
Write the following Lisp functions.
- (splice L1 L2) takes two lists,
and produces a list L3 whose elements are two-element lists containing
the elements of L1 and L2. For example (splice '(1 2 3) '(4 5 6))
returns ((1 4) (2 5) (3 6)).
- (ladd L1 L2), (lsub L1 L2), (lmult L1 L2), and (ldiv L1 L2)
each take two lists, and produces a list L3 whose elements
are the sums, differences, products, and divisions of elements from L1 and L2.
L1 and L2 must be the same length.