Created
March 14, 2011 15:33
-
-
Save ostronom/869320 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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))) |
This file contains hidden or 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
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