Skip to main contentCal State San Bernardino
>> [CNS] >> [Comp Sci Dept] >> [R J Botting] >> [CS320 Course Materials] [Text Version] lab/13.html Tue Jan 9 10:19:11 PST 2007
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320 Lab 13 LISP Laboratory Number 3

      Check out New things on the Course Web Page

      [ http://cse.csusb.edu/dick/cs320/ ]

      Goal

      This lab should teach you how to create and use new functions that manipulate lists. You should record your insights and confusions in a new cs320 lab page and link it to you home/index page.

      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

      Hints


    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

    Net
    1. tree::= NIL | leaf | pair,
    2. pair::= (car . cdr),
    3. leaf::=atom,
    4. car::=tree,
    5. cdr::=tree.

    (End of Net)

    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