Created
July 2, 2010 15:23
-
-
Save Chouser/461507 to your computer and use it in GitHub Desktop.
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
; Create a proxy for which call methods return nil instead of throwing an | |
; exception. | |
; | |
; This is an ugly hack. Will probably break in future versions of clojure. | |
; Probably breaks under certain circumstances with current versions of clojure. | |
; May run over your dog. | |
(def nilfn (constantly nil)) | |
(def nilfns | |
(reify | |
clojure.lang.IPersistentMap | |
clojure.lang.ILookup | |
(valAt [_ k] nilfn))) | |
(defmacro nilproxy [class-and-interfaces & [args]] | |
`(let [p# (proxy ~class-and-interfaces ~(or args []))] | |
(init-proxy p# nilfns) | |
p#)) | |
; (.toString (nilproxy [Object])) ;=> nil | |
; (.clone (nilproxy [Object])) ;=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment