以下函数将表构造为列标题titles 和columns 序列的记录序列:
(defn build-table [titles columns]
(apply map (fn [& xs] (zipmap titles xs)) columns))
:titles 的数量应该与 columns 的数量一样多。
例如,
(build-table [:date :temp-min :temp-max] data)
在哪里
(def data ['("Aujourd'hui" "Demain" "25.11" "26.11" "27.11" "28.11" "29.11")
'("2 °C" "2 °C" "1 °C" "0 °C" "-3 °C" "-4 °C" "0 °C")
'("8 °C" "6 °C" "4 °C" "2 °C" "1 °C" "1 °C" "5 °C")])
...产生
({:temp-max "8 °C", :temp-min "2 °C", :date "Aujourd'hui"}
{:temp-max "6 °C", :temp-min "2 °C", :date "Demain"}
{:temp-max "4 °C", :temp-min "1 °C", :date "25.11"}
{:temp-max "2 °C", :temp-min "0 °C", :date "26.11"}
{:temp-max "1 °C", :temp-min "-3 °C", :date "27.11"}
{:temp-max "1 °C", :temp-min "-4 °C", :date "28.11"}
{:temp-max "5 °C", :temp-min "0 °C", :date "29.11"})
这会将所有数据元素保留为字符串。将它们转换为数字,最好是附加单位,可以独立处理。正如他们所写的那样,例如2°C 不是有效的Clojure。