【发布时间】:2016-05-11 17:41:01
【问题描述】:
我确实必须遍历一个向量,该向量又将地图作为其项目。我需要比较下一张地图,有时我需要查看我们之前查看的地图中的内容。因此,有必要具有某种前瞻性/后视功能。我目前的方法有效,但我认为它是丑陋的、单一的 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 '[{}]))))))])
至于data-example的请求,这是vector的一部分:
[{:tag "0", :position "0", :line "0", :stem "dev", :grammarpos "2625", :word "deva"} {:tag "0", :position "0", :line "0", :stem "deva", :grammarpos "4", :word "deva"}]
工作是比较位置、复合等的值,有时向前看,有时向后看。
【问题讨论】:
-
您能否在您的问题中添加一个小型/代表性数据集?如果您可以显示地图矢量中的内容以及您希望从中返回的内容,您可能会获得更明确的帮助。
-
已添加,希望有助于澄清问题。
标签: dictionary clojure iteration