Skip to content

Commit

Permalink
simplify eqlist and create equal?
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilliamson1 committed Oct 16, 2018
1 parent 956cb91 commit f7c32cc
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions eqlist-fuh-real.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
(else (eq? x1 x2))))

(define eqlist?
(lambda ( l1 l2)
(cond
((and (null? l1 ) (null? l2)) #t)
((or (null? l1) (null? l2)) #f)
((and (atom? (car l1 ))(atom? (car l2)))
(and (eqan? (car l1 ) (car l2))
(eqlist? (cdr l1 ) (cdr l2))))
((or (atom? (car l2))(atom? (car l2))) #f)
(else
(and ( eqlist? ( car l1 ) ( car l2))
( eqlist? ( cdr l1 ) ( cdr l2)))))))
(lambda (l1 l2)
(cond
((and (null? l1 )(null? l2)) #t)
((or (null? l1)(null? l2)) #f)
(else
(and (equal? (car l1) (car l2))
(equal? (cdr l1) (cdr l2)))))))

(define equal?
(lambda (s1 s2)
(cond((and (atom? s1)(atom? s2))
(eqan? s1 s2))
((or (atom? s1)(atom? s2)) #f)
(else (eqlist? s1 s2)))))

(display "should be #t")(eqlist? '(((test)) test) '(((test)) test))
(display "should be #t")(eqlist? '(test (test)) '(test (test)))
(display "should be #f")(eqlist? '(test (test)) '(test test))
(display "should be #t")(eqlist? '() '())
(display "should be #f")(eqlist? '(a) '())
(display "should be #f")(eqlist? '() '(a))
Expand All @@ -32,4 +37,31 @@
(display "should be #t")(eqlist? '(a b) '(a b))
(display "should be #t")(eqlist? '(strawberry ice cream) '(strawberry ice cream))
(display "should be #f")(eqlist? '((test) test2) '(test test2))
(display "should be #f")(eqlist? '(test test2) '((test) test2))
;(display "should be #f")(eqlist? '(test test2) '((test) test2))



(equal? '(a b)'(a b))
(equal? '(a b)'(a b c))
(equal? '(a bc)'(a b))
(equal? 'a'(a b))
(equal? '(a b) 'b)
(equal? '(a (b))'(a (b)))
(equal? '((a) b)'((a) b c))
(equal? '(a bc)'(a b))
(equal? 'a'(a b))
(equal? '(a b) 'b)
(equal? '() '())
(equal? 'b '())
(equal? '(a b) '())

(define rember
(lambda (s l)
(cond ((null? l) '())
((equal? (car l) s)
(rember s (cdr l)))
(else (cons (car l)(rember s (cdr l)))))))

(rember 'a '(a b c))
(rember '(a b c) '(z b (a b c) x 4))

0 comments on commit f7c32cc

Please sign in to comment.