This commit is contained in:
Michiel Borkent 2021-03-13 17:04:35 +01:00
parent 6a911fc54f
commit c0e512e304
3 changed files with 51 additions and 42 deletions

2
sci

@ -1 +1 @@
Subproject commit 02409735ac3e085a407352ea3d0fbd29a3777816
Subproject commit 139df5af5ab8e80a4988db45f1c7110ff40f3e8f

View file

@ -10,11 +10,15 @@
(defn method-or [methods k default]
(or (get methods k)
default))
(constantly default)))
(defn proxy-fn [{:keys [class methods]}]
(case (.getName ^Class class)
"clojure.lang.APersistentMap"
(defn class-name [^Class clazz]
(.getName clazz))
(defn proxy-fn [{:keys [class interfaces methods]}]
(let [interfaces (set (map class-name interfaces))]
(case [(class-name class) interfaces ]
["clojure.lang.APersistentMap" #{"clojure.lang.IMeta" "clojure.lang.IObj"}]
(proxy [clojure.lang.APersistentMap clojure.lang.IMeta clojure.lang.IObj] []
(iterator [] ((method-or-bust methods 'iterator) this))
(containsKey [k] ((method-or-bust methods 'containsKey) this k))
@ -37,16 +41,16 @@
(proxy-super equiv other)))
(empty [] ((method-or-bust methods 'empty) this))
(meta [] ((method-or methods 'meta nil) this))
(withMeta [meta] ((method-or methods 'withMeta this) this meta))
(meta [] ((method-or-bust methods 'meta) this))
(withMeta [meta] ((method-or-bust methods 'withMeta) this meta))
(toString []
(if-let [m (get methods 'toString)]
(m this)
(proxy-super toString))))
"clojure.lang.AMapEntry"
["clojure.lang.AMapEntry" #{}]
(proxy [clojure.lang.AMapEntry] []
(key [] ((method-or-bust methods 'key) this))
(val [] ((method-or-bust methods 'val) this))
(getKey [] ((method-or-bust methods 'getKey) this))
(getValue [] ((method-or-bust methods 'getValue) this)))))
(getValue [] ((method-or-bust methods 'getValue) this))))))

View file

@ -21,7 +21,7 @@
(defn proxy-deref-map
{:added "1.0"}
[m]
(proxy [clojure.lang.APersistentMap]
(proxy [clojure.lang.APersistentMap clojure.lang.IMeta clojure.lang.IObj]
[]
(iterator []
::TODO)
@ -37,7 +37,9 @@
(without [k] (proxy-deref-map (dissoc m k)))
(seq [] (map (fn [[k v]](proxy [clojure.lang.AMapEntry] []
(key [] k)
(val [] (auto-deref (get m k))))) m))))
(val [] (auto-deref (get m k))))) m))
(withMeta [md] (proxy-deref-map (with-meta m md)))
(meta [] (meta m))))
(let [m (proxy-deref-map
{:a (delay 1)
:b (delay 2)
@ -54,10 +56,13 @@
:d)
(-> (dissoc m :a)
(contains? :a))
(seq m)])))
(seq m)
(meta (with-meta m {:a 1}))
])))
(deftest APersistentMap-proxy-test
(is (= [1 2 3 true [:c 3]
5 3 5 false
'([:a 1] [:b 2] [:c 3])]
'([:a 1] [:b 2] [:c 3])
{:a 1}]
(bb code))))