From jacobson@math-cs.cns.uni.edu Wed Jan 21 10:56:18 2004 Date: Wed, 21 Jan 2004 10:52:12 -0600 (CST) From: Mark Jacobson To: 810-151-04@uni.edu Subject: [810-151-04] Printout Scheme assignment #1 due on Friday... Hi 810:151 Scheme students, For your intersection assignment due on Friday: 1. Turn in a printout that includes the following: a. The intersection function that you defined. You can include any other functions you defined along with it. Feel welcome to use the member? function and the page 213 of textbook isList? function, if you wish when you implement your solution. (They are shown below). b. Demonstration that the intersection function works on: i. an empty list and an empty list ii. a list that is a subset of the 2nd list iii. a list that is a superset of the 2nd list iv. the list '(P A N T H E R S) and the list '(H A W K E Y S) v. two lists of your own choosing that have no elements in common. Copy and paste your interactions into another document and print them. Or you can use Print Interactions. c. A few brief notes on whatever you had the most trouble with in doing the assignment, whether slimers (bugs) or the environment or the recursion thinking, etc. Just a few reflections on what gave problems or what you learned. -------------------------------------------------------------------------- NOTE: member is built into Scheme. member returns a list or #f member? is NOT built into Scheme. member? returns #t or #f --- Welcome to DrScheme, version 205. Language: Advanced Student. <----- Student version needs #t or #f > (member? 22 '(11 22 33)) true <----- member? gives it the #t TRUE > (member? 88 '(11 22 33)) false <----- Student version shows output as true or false, but Scheme shows it as #t or #f in output. (define isList? (lambda (val) ; Note: see page 213 of textbook (cond ((null? val) #t) ((pair? val) (isList? (cdr val))) (else #f)))) (define member? (lambda (n li) (isList? (member n li)))) Welcome to DrScheme, version 205. Language: Intermediate Student with lambda. > (member 'comments '(comments are done with semicolons)) (list 'comments 'are 'done 'with 'semicolons) > (member? 'comments '(comments are done with semicolons)) true > (member? 'required '(comments are done with semicolons)) false ; Written by Mark Jacobson - January 21st, 2004 ; Recall that (member 22 (11 22 33)) returns the list (22 33) instead of ; returning #t (shown as true in student (define isList? (lambda (val) ; version (cond ((null? val) #t) ((pair? val) (isList? (cdr val))) (else #f)))) ; See page 213 of the textbook for the above definition. (define member? (lambda (n li) ; <----- Definining member? (isList? (member n li)))) ; <----- Using member without ? See you on Friday in class. http://www.cns.uni.edu/~jacobson/scheme/ Mark