Let me know by
calling me across to your workstation when done.
To earn full credit the work must be done before the end of the lab and
should contain a list of at least a note. The note is a short paragraph
with one or two
sentences, a new LISP function, and a description of what it does.
Required Work
Use a text editor and the XLISP system to develop
a working solution in LISP to one of the problems
set in the class today.
Deliverables
An addition to your web site with links to a couple
of functions from the problems at the end of Chapter 15 of Sebesta
that we covered in class. Add what you have learned by coding and debugging them.
Resources
:set showmatch
Review -- Displaying the structure of a LISP value
LISP data is stored in what is called a binary tree: each item
of data is a "leaf"(an atom), empty (NIL) or a pair (car . cdr).
We call the car and cdr of a pair the branches:
((1 . 2) . 3)The data looks like this (with a 'o' replacing the '.').
o
/ \
o 3
/ \
1 2
Down load/Save this file as text: [ show.lsp ]
Use this UNIX command to look inside the file:
cat show.lsp
Run this UNIX command in a terminal window:
xlisp show.lsp
Inside the running XLISP try these command:
SHOW
(show '(a b))
(show '(a b c))
(show '(a b c d))
(show '((a b)(c d)))
This function (or something like it) is a handy tool when you want to see the structure of a complex list structure.... for example the value show itself.
(show show)
To Leave LISP
To exit lisp, input the EOT character CTRL/D
. . . . . . . . . ( end of section CS320 Lab 13 LISP Laboratory Number 3) <<Contents | End>>
Dirty LISP
It is possible to write LISP code that is full of
loops and the equivalent of {...} and assignments.
The key operators are: PROG, PROGN, DO, DO*,...
You should resist the temptation to use these since your task is to learn functional thinking... which avoids these concepts.
In more advanced classes you may use (LET ....) and (LET* ....)
to avoid an intermediate function.
Check the Preparation for next class
[ ../14.html ]
Want to learn more LISP?
Here you can develop a game, expression by expression
[ http://www.lisperati.com/ ]
( when I tried this I had to define at least one extra
function: (defun push (item place) (setf place (cons item place)))
)
or follow the links on my
[ ../../samples/lisp.html ]
page.
End