On Wed, Jun 15, 2011 at 3:53 PM, RJ Nowling <rnowl...@gmail.com> wrote:
> Hi,
>
> I'm sorry if this has been asked before, but I would like to know how
> to create data structures in Clojure that can be used in the same way
> as the built-in data structures.  For example, I can access the
> elements of a vector by (my-vec 1).  How can I implement this
> interface when creating a data structure in Clojure?

(defrecord Foo [...]
  ...
  IFn
  (invoke [this] (do-this-on-zero-argument-call))
  (invoke [this x] (do-when-called-with-x))
  (invoke [this x y] (+ x y)))

=> ((Foo.) 33 9)
42
=>

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to