Skip to main contentCal State San Bernardino / [CNS] / [Comp Sci Dept] / [R J Botting] / [CSci320] [Search ]
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Sessions: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
13.html (HTML) [13.txt(Text)] Fri Jan 12 12:37:19 PST 2007

Contents


    CS320/13 Functional Programming and Chapter 15

      Prev 12Implementing subprogramsChapter 10 but not 10.3.4.2lab12 LISP102
      13Functional ProgrammingChapter 15 not section 8lab13 LISP103
      Next 14Data AbstractionChapter 2 section 14 + Chapter 11lab14 C/C++ ADTs

      Preparation


        1. Look at the [ Supplement to Chapter 15 ] below.
        2. Study chapter 15 but not sections 15.7 and 15.8.
        3. Think about chapter 15 and try the Extra Exercises below.
        4. Answer the chapter's review questions (ignore questions on ML and Haskell)
        5. Hand in answers 3 or more review questions at the start of class.

        Supplement to Chapter 15

        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:

        PageFunction to Trace
        638member
        640equal
        640append

        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:

        PageSchemeXLISPNote
        630DEFINE-OK for functions in our XLISP, but see Note below
        631EVEN?evenpP stands for Predicate
        "ODD?oddp
        "ZERO?zerop
        "EQV=
        633DISPLAY -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 Print a list of values on a new line
        "NEWLINEterpri terminate print line
        638#Tt
        "#Fnil
        633ELSEt
        637EQ?eq
        "LIST?conspI think.
        "ATOM?atom
        "NULL?null
        638memberPredefined in XLISP
        640appendPredefined in XLISP
        643...mapcar--Predefined in XLISP

        Note

        The XLISP version of DEFINE works for functions not constant terms:
      1. (DEFINE x 10) on page 630 must be translated to
      2. (SETQ x 10).

        To get the static scoping use the defun operator:

      3. (DEFUN name (args) expression) in place of
      4. (DEFINE (name args) expression) Notice how the parentheses move when you shift from Scheme to XLISP!

      . . . . . . . . . ( 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

    1. (CAR Y) is A and
    2. (CDR Y) is B

      We would draw a picture of the memory of the computer like this: [ A | B ]

      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: [ A | -]-->[ B | NIL] [ A | -]-->[ B | NIL] In the above diagram

    3. (CAR Z) is A and
    4. (CDR Z) is (B . NIL) or (B) for short.

      Class Work

      [ 13q.html ]

    Lab Work

    [ lab/13.html ]

    Next

    [ 14.html ]

End