多个返回值

函数

;; 没有元组类型:多个结果放在向量中返回
(defn get-first-last [coll]
  (if (seq coll)
    [(first coll) (last coll)]
    [-1 -1]))

;; 解构在调用处把向量拆开
(let [[fst lst] (get-first-last [2 3 5])]
  (println "first is" fst)
  (println "last is" lst))

;; 当各部分值得命名时,返回映射
(defn get-bounds [coll]
  {:min (apply min coll) :max (apply max coll)})

(let [bounds (get-bounds [2 3 5])]
  (println "min is" (:min bounds) "max is" (:max bounds)))