Skip to content

Instantly share code, notes, and snippets.

@branch14
Last active May 27, 2017 08:41
Show Gist options
  • Save branch14/5542b12d1b3d04867cbdb8d4a4ae0bea to your computer and use it in GitHub Desktop.
Save branch14/5542b12d1b3d04867cbdb8d4a4ae0bea to your computer and use it in GitHub Desktop.
Problem with proxy of PersistentArrayMap
(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