【SICP练习】82 练习2.54

这些关于Scheme的基本知识在【Scheme归纳】系列博文总都有介绍。

(define (equal? x y)
     (cond ((and (symbol? x) (symbol? y))  
             (symbol-equal? x y))
            ((and (list? x) (list? y))
             (list-equal? x y))
            (else 
             (error “Error: You just input wrong type.”))
(define (symbol-equal? x y)
(eq? x y))
(define (list-equal? x y)
(cond ((and (null? x) (null? y))
        #t)
       ((or (null? x) (null? y))
        #f)
       ((equal? (car x) (car y))
        (equal? (cdr x) (cdr y)))
       (else #f)))

在倒数第二行中运用了递归。



感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。


为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp


版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

原文地址:https://www.cnblogs.com/NoMasp/p/4786137.html