Hi,
I recently wrote some code for which I have 2 alternative implementations.
So what I did is write a protocol:

(defprotocol Calculator
     (calc-add [this data])
 (calc-multiply [this data]))
 
  
I then created two namespaces for my two implementations:
which each had a function:

(defn make-calculator []
  (reify Calculator
    (calc-add [this data] .....)
 (calc-multiply [this data]....))
 
So my core code was using this protocol and I can switch  implementation by 
just handing my "protocol-using-code" a different make-calculator.

But am I really doing programming in a functional style?
 
I mean I am creating with reify a class only so that my different 
implementation gets called.
This "reify" makes me think "this is not functional but more OO like".

On the other hand it is very nice to have a "grouping of certain functions" 
and it makes it clear this protocol 
is a plugin point for custom implementations.

I don't know?! Am I just complaining about perfect readable side effect 
free code? 

Many Greetings
John

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to