| Prev 12 | Implementing subprograms | Chapter 10 but not 10.3.4.2 | lab12 LISP102 |
| 13 | Functional Programming | Chapter 15 not section 8 | lab13 LISP103 |
| Next 14 | Data Abstraction | Chapter 2 section 14 + Chapter 11 | lab14 C/C++ ADTs |
I am likely to ask you to program a simple LISP function in the final. These are the kinds of functions that are examples in section 15.5.5 or solutions to one or more the first 5 Problems at the end of the chapter. We will practice functions like these in the next class and in the lab.
Extra Exercise
Invent a test case and trace, step by step, what the following functions do
according to their definitions in the book:
| Page | Function to Trace |
|---|---|
| 638 | member |
| 640 | equal |
| 640 | append |
You can try them out and TRACE them on our computers using XLISP, as long as you translate them.
Translation (Book -> Lab)
Nearly all of the book's Scheme examples(pages 628-644) will work with our
XLISP if you change words as below:
| Page | Scheme | XLISP | Note |
|---|---|---|---|
| 630 | DEFINE | - | OK for functions in our XLISP, but see Note below |
| 631 | EVEN? | evenp | P stands for Predicate |
| " | ODD? | oddp | |
| " | ZERO? | zerop | |
| " | EQV | = | |
| 633 | DISPLAY - | Depends on the precise semantics of DISPLAY, Try one of these | |
| " | " | Prin1 | Print a list of values |
| " | " | Princ | Print a list of values without quoting |
| " | " | Print a list of values on a new line | |
| " | NEWLINE | terpri | terminate print line |
| 638 | #T | t | |
| " | #F | nil | |
| 633 | ELSE | t | |
| 637 | EQ? | eq | |
| " | LIST? | consp | I think. |
| " | ATOM? | atom | |
| " | NULL? | null | |
| 638 | member | Predefined in XLISP | |
| 640 | append | Predefined in XLISP | |
| 643... | mapcar | --Predefined in XLISP |
To get the static scoping use the defun operator:
. . . . . . . . . ( end of section Preparation) <<Contents | End>>
Reminders about LISP
LISP makes data structures using dotted pairs. A dotted pair is an object
with two parts called: CAR and CDR.
If Y has value (A . B) (notice the dot), then
We would draw a picture of the memory of the computer like
this:
If Z is a variable that has a simple list (A B ) (notice the absence of a
dot between A and B!) then the
B is in a second dotted pair, linked to the first one like this:
In the above diagram