2
원자로 뒷받침 된 클로저 스크립트에 concept of a Cursor을 빌드하려고합니다. 커서는 변경 불가능한 중첩 된 관련 데이터 구조를 편집하기위한 재귀 지퍼와 같은 메커니즘입니다.프로토콜로 어려움을 겪고있는 Clojure 초보자
저는 Clojure에서 매우 초보자입니다. 제 실수를 발견하도록 도와 줄 수 있습니까?
(defprotocol Cursor
(refine [this path])
(set [this value])
(value [this]))
(defn- build-cursor* [state-atom paths]
(reify Cursor
(set [this value] (swap! state-atom (assoc-in @state-atom paths value)))
(refine [this path] (build-cursor* state-atom (conj paths path)))
(value [this] (get-in @state-atom paths))))
(defn build-cursor [state-atom]
(build-cursor* state-atom []))
(comment
(def s (atom {:a 42}))
(def c (build-cursor s))
(assert (= (value c) {:a 42}))
(set c {:a 43}) ;; WARNING: Wrong number of args (2) passed to quiescent-json-editor.core/set at line 1 <cljs repl>
(assert (= (value c) {:a 43}))
(def ca (refine c :a)) ;; WARNING: Wrong number of args (2) passed to quiescent-json-editor.core/refine at line 1 <cljs repl>
(assert (= (value ca) 43))
(set ca 44)
(assert (= (value ca) 43))
)
JIRA 문제 : 다음은
내 테스트 코드입니다 http://dev.clojure.org/jira/browse/CLJ-1520 – lnmx