[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /13.html [13.txt(Text)] [Search ]
Mon Mar 5 20:27:14 PST 2012
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]


    CS320/13 Functional Programming and Chapter 15

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

      (Close Table)


        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 2 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.10 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

        (Close Table)

        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 682-707) will work with our XLISP if you change words as below:

        666DEFINE-OK for functions in our XLISP, but see Note below
        683,684DEFINE-OK for functions in our XLISP, but see Note below
        684DISPLAY -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
        685EVEN?evenpP stands for Predicate
        690EQ?eqBuilt in
        690LIST?conspI think.
        692memberPredefined in XLISP
        693appendPredefined in XLISP
        697composeTo Be Announced!
        698...mapcarPredefined in XLISP

        (Close Table)


        The XLISP version of DEFINE works for functions. It will not define constant terms:
      1. (DEFINE x 10) on page 683 and 684 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 ]


    [ 14.html ]