yazz.com
yazz.com

Reputation: 58786

How to use clojure hierarchies?

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?

Upvotes: 5

Views: 960

Answers (1)

Michael Kohl
Michael Kohl

Reputation: 66837

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/

Upvotes: 5

Related Questions