-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_2_54.clj
28 lines (26 loc) · 839 Bytes
/
ex_2_54.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns sicp.chapter-2.part-3.ex-2-54)
; Exercise 2.54
;
; Two lists are said to be equal? if they contain equal elements arranged in the same order.
; For example,
;
; (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 a and b are equal? if they are both symbols and the
; symbols are eq?, or if they are both lists such that (car a) is equal? to (car b) and (cdr a)
; is equal? to (cdr b). Using this idea, implement equal? as a procedure.
(defn equal?
[a b]
(cond
(and (symbol? a) (symbol? b)) (= a b)
(and (list? a) (list? b))
(and (= (count a) (count b)) (every? true? (map equal? a b)))
:else false))