Skip to content

Instantly share code, notes, and snippets.

@michalmarczyk
Created April 24, 2010 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalmarczyk/377480 to your computer and use it in GitHub Desktop.
Save michalmarczyk/377480 to your computer and use it in GitHub Desktop.
fooling around with Clojure interfaces, part 1
(deftype Foo [x y z]
clojure.lang.IKeywordLookup
(getLookupThunk
[self k]
(reify
clojure.lang.ILookupThunk
(get
[self k]
(if-let [v (k {:x x :y y :z z})]
(inc v)))))
clojure.lang.IFn
(invoke
[self k]
(.get (.getLookupThunk self k) k))
clojure.lang.ILookup
(valAt
[self k]
({:x x :y y :z z} k))
(valAt
[self k nf]
({:x x :y y :z z} k nf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment