.Open CS320/13 Functional Programming and Chapter 15 .Table .Row Prev 12 Implementing subprograms Chapter 10 lab12 LISP102 .Row 13 Functional Programming Chapter 15 not section 8 lab13 LISP103 .Row Next 14 Data Abstraction Chapter 2 section 14 + Chapter 11 lab14 C/C++ ADTs .Close.Table .Open Preparation .List Look at the .See Supplement to Chapter 15 below. Study chapter 15 but not sections 15.7 and 15.8. Think about chapter 15 and try the Extra Exercises below. Answer the chapter's review questions (ignore questions on ML and Haskell) Hand in answers 2 or more review questions at the start of class. .Close.List . 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: .Table Page Function to Trace .Row 692 member .Row 693 equal .Row 694 append .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: .Table Page Scheme XLISP Note .Row 666 DEFINE - OK for functions in our XLISP, but see $Note below .Row 683,684 DEFINE - OK for functions in our XLISP, but see $Note below .Row 684 DISPLAY - Depends on the precise semantics of DISPLAY, Try one of these .Row " " Prin1 Print a list of values .Row " " Princ Print a list of values without quoting .Row " " Print Print a list of values on a new line .Row " NEWLINE terpri terminate print line .Row 685 EVEN? evenp P stands for Predicate .Row " ODD? oddp .Row " ZERO? zerop .Row " EQV = .Row 685 #T t .Row " #F nil .Row 686 ELSE t .Row 690 EQ? eq Built in .Row 690 LIST? consp I think. .Row " ATOM? atom .Row 691 NULL? null .Row 692 member Predefined in XLISP .Row 693 append Predefined in XLISP .Row 697 compose To Be Announced! .Row 698... mapcar Predefined in XLISP .Close.Table . Note The XLISP version of DEFINE works for functions. It will not define constant terms: (DEFINE x 10) on page 683 and 684 must be translated to (SETQ x 10). To get the static scoping use the `defun` operator: (DEFUN name (args) expression) in place of (DEFINE (name args) expression) Notice how the parentheses move when you shift from Scheme to XLISP! .Close Preparation . 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 (CAR Y) is A and (CDR Y) is B We would draw a picture of the memory of the computer like this: .Image 14/ole.gif [ 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: .Image 14/ole1.gif [ A | -]-->[ B | NIL] [ A | -]-->[ B | NIL] In the above diagram (CAR Z) is A and (CDR Z) is (B . NIL) or (B) for short. . Class Work .See ./13q.html .Close . Lab Work .See ./lab/13.html . Next .See ./14.html