Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use clojure hierarchies?

Tags:

clojure

I am trying to understand how Clojure hierarchies work, with the derive and is-a? constructs. I'm not sure how I would use these with the maps and records in my program. Has anyone used these?

like image 390
yazz.com Avatar asked Jan 03 '11 09:01

yazz.com


1 Answers

I find your question a bit vague. Have you read the documentation on the Clojure website?

http://clojure.org/multimethods

I find the examples there quite easy to follow:

user=> ::rect
:user/rect
user=> (derive ::rect ::shape)
nil
user=> (parents ::rect)
#{:user/shape}
user=> (derive ::square ::rect)
nil
user=> (ancestors ::square)
#{:user/shape :user/rect}
user=> (isa? ::square ::shape)
true

There's also this blog post with a more "real-world" example:

http://www.prodevtips.com/2010/06/20/clojure-inheritance/

like image 179
Michael Kohl Avatar answered Oct 25 '22 04:10

Michael Kohl