2 Replies - 2693 Views - Last Post: 07 April 2010 - 12:12 AM

#1 YamNad  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 120
  • Joined: 11-July 09

Clojure defprotocol and deftype

Posted 06 April 2010 - 04:36 PM

I would usually have asked this on (another community) or in #clojure, but I figured the Functional Programming forum needs a bit of action - and I can wait a while for an answer.

On topic:

Would it be considered an appropriate use of defprotocol and deftype to do the following, or have I got the wrong idea?

(defprotocol Weather
  (location [feed] "Extracts the location from the feed.")
  (temperature [feed] "Extracts the temperature from the feed."))


(With many more methods, of course.)

And then, depending on the API I'm extracting the data from, to create a (def)type for each? e.g. Yahoo Weather

Finally, assuming the response to the previous question is yes, would this now be considered the best way to achieve the aim?

I could probably have made this thread personal by addressing Raynes directly, but just in case... :)

This post has been edited by YamNad: 06 April 2010 - 05:18 PM


Is This A Good Question/Topic? 1
  • +

Replies To: Clojure defprotocol and deftype

#2 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Clojure defprotocol and deftype

Posted 06 April 2010 - 11:50 PM

You've got the right idea. You define abstractions with defprotocol, and implement them with deftype. This sounds like a fine usage of defprotocal and deftype. I'm not sure if it's the /best/ way to achieve this, but I can't think of a better way.

Weather is generally always the same, no matter what service you get that data from, so it seems perfectly logical to abstract Weather. I think you're on the right course.

Also, sorry for the delay. I'm going to subscribe to this forum so I don't miss stuff like this again.

This post has been edited by Raynes: 06 April 2010 - 11:52 PM

Was This Post Helpful? 1
  • +
  • -

#3 YamNad  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 120
  • Joined: 11-July 09

Re: Clojure defprotocol and deftype

Posted 07 April 2010 - 12:12 AM

Thanks Raynes.

*Is about to use today completely rewriting his implementation of Clj-Weather.* :P

View PostRaynes, on 07 April 2010 - 06:50 AM, said:

Also, sorry for the delay. I'm going to subscribe to this forum so I don't miss stuff like this again.


Hey, it's fine. You were just-in-time actually - I awoke ~15 minutes ago. :)

This post has been edited by YamNad: 07 April 2010 - 12:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1