Complex Systems, Spring 1998
Paul Grobstein, Bryn
Mawr College Department of Biology
Clare Congdon, Bryn Mawr
College Computer Science Program
When you're running Lisp, you'll have a new prompt, the angle bracket. Most of the legitimate things to type should be enclosed in parentheses, such as (exit). The parentheses are absolutely important. (Some folks will claim that LISP is an acronym for Lots of Irritating and Silly Parentheses. But it really stands for LISt Processing language. The parentheses are used to denote the lists.)
Lisp curiosities
(+ 3 5)
3
(* (+ 3 5) (- 10 2))
The expressions are evaluated from left to right and from the inside
out, so the above is equivalent to (* 8 5)
abort
(setf x 3)
(setf y 5)
(+ x y)
Variables will be created on the fly. (They will be globals variables, but
we don't have to worry about that.)
Notice that if you type the above three lines, the first expression will return 3, the second will return 5, and the third will return 8.
For this lab, we will only be using logical functions as the primitives for our genetic programming.
For the purposes of the following examples, lets define a few variables:
(setf w T)
(setf x T)
(setf y NIL)
(setf z NIL)
(and w x) --> T
(and w y) --> NIL
(and y z) --> NIL
(or w x) --> T
(or w y) --> T
(or y z) --> NIL
Note that this is not an exclusive or.
(not w) --> NIL
(not y) --> T
(equal w x) --> T
(equal w y) --> NIL
(equal y z) --> T
Programmers can think of this as
if (the 1st expression is T)
then (evaluate the 2nd expression)
else (evaluate the 3rd expression)
But you still have to think in Lisp terms with that.
This will take a little while to sink in for all of you, but here's some examples:
(if x y z) --> NIL (x is T, so y is returned)
(if y x w) --> T (y is NIL, so w is returned)
(if (and w x)
x
z) --> T ((and w x) is T, so x is returned)
(and (or y (not z)) (equal (or y z) (and x y)))The above expression evaluates to T (which you can try out for yourself by first doing all the SETF's for the variables and then typing the expression at the Lisp prompt.) From the inside out,
It may be easier at first to type these things at the Lisp prompt rather than trying to figure it out in your head, so that you get a feel for the T and NIL convention.
Maintained by: