Seb*_*_學生 2 iteration dictionary clojure
我必须迭代一个矢量,而矢量又将地图作为其项目.我需要比较下一张地图,有时我需要查看我们之前看过的地图.所以有必要展望未来/看后面的功能.我当前的方法是有效的,但我想这是丑陋的,单一的Clojure,我认为必须有更好的(更规范的)方法来实现这一点.
(let [result (apply str (map (fn [{position-before :position compound-before :compund } ; previous term (unfortunately we need to compare all three)
{:keys [word position line tag stem compound grammarpos] :or {grammarpos "0" stem "" } } ; this maps to the current word
{position-ahead :position compound-ahead :compound line-ahead :line}] ; this is for lookahead
(do some stuff)) ;; now we have position, which is our current position, position-before and position-after to compare with each other
;; this is how we map:
(into '[{}] (conj grammar '[{}]))
(next (into '[{}] (conj grammar '[{}])))
(next (next (into '[{}] (conj grammar '[{}]))))))])
Run Code Online (Sandbox Code Playgroud)
至于数据示例的请求,这是向量的一部分:
[{:tag "0", :position "0", :line "0", :stem "dev", :grammarpos "2625", :word "deva"} {:tag "0", :position "0", :line "0", :stem "deva", :grammarpos "4", :word "deva"}]
Run Code Online (Sandbox Code Playgroud)
工作是比较位置,复合等的值,有时向前看,有时看后面.
joh*_*ers 12
你可以迭代你的一个partition矢量,大小为3,步长为1.然后,对于矢量中的每个元素,你也可以获得之前和之后你可以用for或者迭代来学习reduce.
一些例子:https://clojuredocs.org/clojure.core/partition