yes that seems to me, that this better expresses that I'm plugging in a
set of functions.
thanks
Am Mittwoch, 5. Juni 2013 12:55:16 UTC+2 schrieb Moritz Ulrich:
>
> If you want to keep this style, why not use a simple map of function
> instead of reifying a protocol? Something like:
>
> (defn calc-multiply [data] ...)
> (defn calc-add [data] ...)
> (defn make-calc [] {:calc-add #'calc-add, :calc-multiply #'calc-multiply})
>
> Looks simpler and cleaner for me.
>
> On Wed, Jun 5, 2013 at 12:16 PM, john <[email protected] <javascript:>>
> wrote:
> > 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 [email protected]<javascript:>
> > Note that posts from new members are moderated - please be patient with
> your
> > first post.
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>
> > 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 [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.