Clojure第一天作业

来源:互联网 发布:淘宝店铺刷收藏 编辑:程序博客网 时间:2024/05/04 15:59

1.实现一个函数(big st n),当字符串长度不超过n个字符时返回true.

(defn big [st n] (< (count st) n))(big "aaaa" 3)   // false(big "aaaa" 5)   // true

2.实现一个函数(collection-type col),根据给定集合col的类型返回:list,:map,:vector

(defn collection-type [col] (if (list? col) :list (if (map? col) :map :vector)))(collection-type '(1 2 3))(collection-type {:a 1, :b 2})(collection-type [1 2 3])// (collection-type #{1 2 3})  // hashset


0 0