# Rick van der Zwet # StudentID: 0433373 # $Id: lecture6.txt 339 2007-11-29 22:01:09Z rick $ All quotes are based on the 8th edition of Concepts of programming languages from Robert W. Sebesta *** Chapter 15 Review Questions *** Problem Set 6,7 6) Q: What does the following Scheme function do? (define (y s lis) (cond ((null? lis) '() ) ((equal? s (car lis)) lis) (else (y s (cdr lis))) A: It will remove the head of the list till it find s, if none found '() is the result 7) Q: What does the following Scheme function do? (define (x lis) (cond ((null? lis) 0) ((not (list? (car list))) (cond ((eq? (car lis) nil) (x (cdr lis))) ((else (+ 1 (x (cdr list)))))) (else (+ (x (car list)) (x cdr lis)))) )) A: It will traverse the lis and count the number of atoms in there Problem Excercises 4,5,6 4) Q: Write Scheme function that returns the number of zeros in a given simple list of numbers. A: (define (x lis) (cond ((null? lis) 0) ((eq? 0 (car lis)) (+ 1 (x (cdr lis))) (else (+ 0 (x (cdr lis))) ) ) 5) Q: Write a Scheme function that deletes all top-level instances of an given atom from a given list A: (define (x atom lis) (cond ((null? lis) '() ) ((eq? atom lis) (x atom cdr(lis))) ((else (cons car(atom) (x atom cdr(lis))))) ) ) 6) Q: Write a Scheme function that removes the last element from a given list (define (x list) (cond ((null? cdr(list) '() )) ((else (cons car(list) (x cdr(list))))) ) )