Last active
May 27, 2017 08:41
-
-
Save branch14/5542b12d1b3d04867cbdb8d4a4ae0bea to your computer and use it in GitHub Desktop.
Problem with proxy of PersistentArrayMap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn with-fallback [amap fallback-fn] | |
(proxy [clojure.lang.PersistentArrayMap | |
clojure.lang.IFn] | |
[(into-array Object amap)] | |
(invoke [key] (or (get amap key) | |
(fallback-fn amap key))))) | |
(def a (with-fallback {:a 1} | |
(fn [amap key] (str "no value for " key " in " amap)))) | |
(a :a) ;=> 1 | |
(a :b) ;=> "no value for :b in {:a 1}" | |
(assoc a :c 2) | |
;but this yields a "Unhandled java.lang.ArrayIndexOutOfBoundsException" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment