: 장소에와
(def ^:private ipm-print-method
(get (methods print-method) clojure.lang.IPersistentMap))
(defmethod print-method clojure.lang.PersistentTreeMap
[o ^java.io.Writer w]
(.write w "#sorted/map ")
(ipm-print-method o w))
에서 data_readers.clj
:
{sorted/map my-app.core/create-sorted-map}
참고 :이 일하는 것이 좋겠다고 생각하지만, (이유는 확실하지)하지 않았다 :
{sorted/map clojure.lang.PersistentTreeMap/create}
이제 my-app.core
에 : 대안으로
(defn create-sorted-map
[x]
(clojure.lang.PersistentTreeMap/create x))
(defmethod print-method clojure.lang.PersistentTreeMap
[o ^java.io.Writer w]
(.write w "#sorted/map ")
(print-method (into {} o) w))
- 적은 낮은 -Level, 당신은 사용할 수 있습니다
(defn create-sorted-map [x] (into (sorted-map) x))
테스트를 :
(deftest reader-literal-test
(testing "#sorted/map"
(is (= (sorted-map :v 4 :w 5 :x 6 :y 7 :z 8)
#sorted/map {:v 4 :w 5 :x 6 :y 7 :z 8}))))
(deftest str-test
(testing "str"
(is (= "#sorted/map {:v 4, :w 5, :x 6, :y 7, :z 8}"
(str (sorted-map :v 4 :w 5 :x 6 :y 7 :z 8))))))
이 중 많은 부분이 위에서 찾은 자료에서 수정되었습니다.
참고 : 위의 print-method
작동에 놀랐습니다. (into {} o)
은 주문을 잃어 버리므로 인쇄를 중단하는 것처럼 보일 수 있지만 내 테스트에서는 작동합니다. 나는 이유를 모른다.
NB. 'clojure.edn' 네임 스페이스가 Clojure 1.5에 도입되었습니다. –