用Clojure学习The Little Schemer时的一些基本函数定义

时间:2014-08-13 10:44:55   收藏:0   阅读:387
;; learning The Little Schemer

(def car first)
(def cdr rest)
(def cons clojure.core/cons)
(def eq? =)
(def list? clojure.core/list?)
(defn atom? [x]
  (not (list? x)))

(defn s-exp? [x]
  (or (atom? x) (list? x)))

(defn null? [x]
  (if (atom? x) (car x) ;raise a exception
      (and (list? x) (empty? x))))


抛出异常的地方是为了保持“未定义”语义,即书中说到的 “you cannot do this”

用Clojure学习The Little Schemer时的一些基本函数定义,布布扣,bubuko.com

原文:http://my.oschina.net/wardenlym/blog/300610

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!