.Open CS320/13 Functional Programming and Chapter 15 .Table .Row Prev 12 Implementing subprograms Chapter 10 but not 10.3.4.2 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 3 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.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: .Table Page Function to Trace .Row 660 member .Row 661-2 equal .Row 662 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 650-666) will work with our XLISP if you change words as below: .Table Page Scheme XLISP Note .Row 652 DEFINE - OK for functions in our XLISP, but see $Note below .Row 653 EVEN? evenp P stands for Predicate .Row " ODD? oddp .Row " ZERO? zerop .Row " EQV = .Row 653 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 654 #T t .Row " #F nil .Row 655 ELSE t .Row 658 EQ? eq .Row 659 LIST? consp I think. .Row " ATOM? atom .Row " NULL? null .Row 660 member Predefined in XLISP .Row 661 append Predefined in XLISP .Row 665... 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 652 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