5
votes

So digging around trying to figure out how to do ADTs in Clojure I run into the old clojure-contrib which is well and good except that it's been replaced. Ok no big deal, just go look through the replaced clojure-contrib's catalog of broken apart libraries, but for the life of me I cannot find where defadt was migrated in the new clojure-contrib broken up libraries.

So where has it migrated to?

I've been looking around http://dev.clojure.org/display/doc/Clojure+Contrib+Libraries but can't figure it out.

bonus points if you can give me the string to hand to alembic.still/distill to get it to plug it in for me.

1
This should probably be posted to Programmers.SE - Jimmy Hoffa
not really: it's a pretty specific question about a programming library. That's definitely on-topic for SO. - mikera

1 Answers

5
votes

The usual style in Clojure isn't to define ADTs. I'd regard the defadt functionality as old / deprecated.

Instead, consider defining your data structures using regular Clojure maps or vectors.

Alternatively you could use deftype or defrecord if you want a named type which can be used for polymorphic dispatch using protocols. This is a flexible and fast way of getting ADT-like behaviour.