Skip to content

Instantly share code, notes, and snippets.

@ostronom
Created March 14, 2011 15:33
Show Gist options
  • Save ostronom/869320 to your computer and use it in GitHub Desktop.
Save ostronom/869320 to your computer and use it in GitHub Desktop.
(ns example.core
(:import clojure.lang.ILookup))
(deftype MyType [a b]
ILookup
(valAt [this key]
(cond
(= key :a) a
(= key :b) (+ b 100500)
:else nil)
(valAt [this key noobj]
(if-let [ret (key this)] ret noobj)))
user=> (use 'example.core)
nil
user=> (in-ns 'example.core)
#<Namespace example.core>
example.core=> (def mt (MyType. 1 2))
#'example.core/mt
example.core=> (:a mt)
1
example.core=> (:b mt)
100502
example.core=> (:c mt)
nil
example.core=> (:c mt 15)
15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment