我正在使用docjure,它的select-columns函数需要一个列映射.我想抓住我的所有列而不必手动指定它.如何生成以下作为惰性无限向量序列[:A:B:C:D:E ...:AA:AB:AC ....:ZZ ......:XFD]?
(defn state [t]
(reduce (fn [[s1 t1] [s2 t2]]
(if (>= t1 t) (**reduced** s1) [s2 (+ t1 t2)]))
(thomsons-lamp)))
Run Code Online (Sandbox Code Playgroud)
我查看了文档和源代码,无法完全理解它.
(defn reduced
"Wraps x in a way such that a reduce will terminate with the value x"
{:added "1.5"}
[x]
(clojure.lang.Reduced. x))
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我认为(reduced s1)应该结束减少并返回s1.
使用reduce +减少等价于假设的reduce-while或reduce-until函数是否存在?
假设我有以下向量
(def x [[1 2 3] [4 5 6] [7 8]])
Run Code Online (Sandbox Code Playgroud)
我想将数字9附加到最后一个向量(我不知道向量的索引)
(conj (vec (butlast x)) (conj (last x) 9))
#=> [[1 2 3] [4 5 6] [7 8 9]]
Run Code Online (Sandbox Code Playgroud)
有没有更好/更清晰的方法来做到这一点?
我很难理解懒惰.
有人可以帮助我理解为什么我的下面的功能不是懒惰的
(defn my-red
([f coll] (my-red f (first coll) (rest coll) ))
([f init coll]
(let [mr (fn [g i c d]
(if (empty? c) d
(recur g (g i (first c)) (rest c) (conj d (g i (first c)) ))))]
(lazy-seq (mr f init coll [])))))
Run Code Online (Sandbox Code Playgroud)
而在clojure.org/lazy上给出的这个例子是
(defn filter
"Returns a lazy sequence of the items in coll for which
(pred item) returns true. pred must be free of side-effects."
[pred coll]
(let [step (fn [p c]
(when-let …Run Code Online (Sandbox Code Playgroud) 为什么我得到2个不同的值
(apply (first '(+ 1 2)) (rest '(+ 1 2)))
> 2
Run Code Online (Sandbox Code Playgroud)
和
(apply + '(1 2))
> 3
Run Code Online (Sandbox Code Playgroud)
什么时候
(first '(+ 1 2))
> +
Run Code Online (Sandbox Code Playgroud)
和
(rest '(+ 1 2))
> (1 2)
Run Code Online (Sandbox Code Playgroud)
我尝试减少并获得相同的价值
(reduce (first '(+ 1 2)) (rest '(+ 1 2)))
> 2
Run Code Online (Sandbox Code Playgroud) xml可以是本机clojure数据类型,并允许简单的定义,如
(def myxml <inventors><clojure>Rich Hickey</clojure></inventors>)
Run Code Online (Sandbox Code Playgroud)
是什么阻止了当前的解析器这样做
{:inventors {:clojure "Rich Hickey"}}
Run Code Online (Sandbox Code Playgroud)
而不是这个
{:tag :inventors, :attrs nil, :content [{:tag :clojure, :attrs nil, :content ["Rich Hickey"]}]}
Run Code Online (Sandbox Code Playgroud)
粗略搜索其他lisps中的类似表示我看到 支持命名空间的SXML.
当我在 clojure repl 中运行它或使用 leiningen repl 时,我的应用程序会运行,但是当我使用 uberjar 创建一个 jar 并运行该应用程序时,它只读取我的集合的前 2 条记录。
我追踪到 pmap,所以我创建了 pmap 的最简单的用法,它变得更奇怪。为什么这有效
(ns ktest.core
(:gen-class))
(defn -main []
(println (pmap identity (range 20))))
Run Code Online (Sandbox Code Playgroud)
但不是这个
(ns ktest.core
(:gen-class))
(defn -main []
(pmap #(println %) (range 20)))
Run Code Online (Sandbox Code Playgroud) 假设我有一张地图矢量
[{:username "kbee" :firstname "Kay" :lastname "Bee"},
{:username "jcee" :firstname "Jay" :lastname "Cee"}]
Run Code Online (Sandbox Code Playgroud)
我想为每个地图生成xml文件,如下所示
<user>
<username>kbee</username>
<firstname>Kay</firstname>
<lastname>Bee</lastname>
</user>
Run Code Online (Sandbox Code Playgroud)
我如何使用clojure核心库来实现这一目标.(我看着活跃和舰队,但对我来说似乎有点复杂.)
理想情况下,我想做以下事情
(map #(spit (str (:username %) ".xml") (gen-xml sometemplate %) map-of-users))
Run Code Online (Sandbox Code Playgroud) 我计划每10分钟运行一次coldfusion模板,当前一次运行超过10分钟时,如何防止它运行.
不幸的是,当模板超时或计数器出错时,我尝试在应用程序范围内使用计数器变量.
PS.是否有用于集成应用程序的coldfuison框架(后端内容)