CSC 415
Homework Assignment #2
Due Date: 11/11/2014

Racket is a new language which includes several versions of Scheme as subsets. The environment is available as a free download from http://racket-lang.orgThere are also links there to Scheme language tutorials and help with the DrRacket environment. You are to write Scheme programs as described in Programming Exercises 3, 11, 12, and 13 on pages 724-725 of your textbook. Below is a sample program that implements and (minimally) tests the functions ‘EQUALSIMP’ and ‘EQUAL’ from pages 692 and 693. This is also available for separate download here (change the name from 'sample.scm.txt' to 'sample.scm').

;
; This is the definition of the function EQUALSIMP
;
(define (EQUALSIMP lis1 lis2)
(cond
((null? lis1) (null? lis2))
((null? lis2) #F)
((eq? (car lis1) (car lis2)) (EQUALSIMP (cdr lis1) (cdr lis2)))
(else #F)
)
)
(define list1 '(a b c d e))
(define list2 '(a b c d e))
(define list3 '(a b c d f))
(display "Testing the function EQUALSIMP ...")
(newline)
(display "list1 = ")
(display list1)
(newline)
(display "list2 = ")
(display list2)
(newline)
(display "Is list1 = list2? ")
(display (EQUALSIMP list1 list2))
(newline)
(display "list3 = ")
(display list3)
(newline)
(display "Is list1 = list3? ")
(display (EQUALSIMP list1 list3))
(newline)
;
; Now let's define the function EQUAL
;
(define (EQUAL lis1 lis2)
(cond
((not (list? lis1)) (eq? lis1 lis2))
((not (list? lis2)) ' ())
((null? lis1) (null? lis2))
((null? lis2) #f)
((EQUAL (car lis1) (car lis2)) (EQUAL (cdr lis1) (cdr lis2)))
(else #f)
)
)
;
; Define some lists to test equal
;
(define list4 '(a b (c d) e () f))
(define list5 '(a b (c d) e () f))
(define list6 '(a b (c d) e () g))
(display "Testing the function EQUAL ...")
(newline)
(display "list4 = ")
(display list4)
(newline)
(display "list5 = ")
(display list5)
(newline)
(display "Is list4 = list5? ")
(display (EQUAL list4 list5))
(newline)
(display "list6 = ")
(display list6)
(newline)
(display "Is list4 = list6? ")
(display (EQUAL list4 list6))
(newline)
;
; Does this function also work for simple lists?
;
(display "Is list1 = list2? ")
(display (EQUAL list1 list2))
(newline)
(display "Is list1 = list3? ")
(display (EQUAL list1 list3))
(newline)