Two lists are said to be
equal?if they contain equal elements arranged in the same order.
(equal? '(this is a list) '(this is a list))
is true, but
(equal? '(this is a list) '(this (is a) list))
is false. To be more precise, we can define
equal?recursively in terms of the basic
eq?equality of symbols by saying that
equal?if they are both symbols and the symbols are
eq?, or if they are both lists such that
(cdr b). Using this idea, implement
equal?as a procedure.
I wrote the following:
(define (equal? a b) (or (and (and (symbol? a) (symbol? b)) (eq? a b)) (and (null? a) (null? b)) (and (and (and (not (null? a)) (list? a)) (and (not (null? b)) (list? b))) (and (equal? (car a) (car b)) (equal? (cdr a) (cdr b))))))
Can this be improved?