Tech behind Tech

Raw information. No finesse :)

Simple clojure multimethod example

leave a comment »


user> (defmulti teller (fn [m] (:tell m)))
#'user/teller
 user> (defmethod teller :b [m] (:b m))
#
 user> (defmethod teller :a [m] (:a m))
#
 user> (def m {:tell :a :a 1 :b 2})
#'user/m
 user> (teller m)
1
 user> (def m {:tell :b :a 1 :b 2})
#'user/m
 user> (teller m)
2

Written by Siva Jagadeesan

June 16, 2010 at 12:33 am

Posted in Clojure

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 146 other followers

%d bloggers like this: