I know that this has come up before on the group and but is this not
essentially dependency injection where the dependency being injected
is a name space that presumably follows a particular convention in
terms of what functions it provides?

I remember people making it pretty clear that they didn't see the need
for DI in Clojure so my question is, is this a useful approach? is
there a better way?

Cheers,
James

On Sep 7, 3:17 pm, Cliff Wells <cl...@twisty-industries.com> wrote:
> Hi,
>
> I'm new to Clojure (and Lisp-type languages in general) and I've never
> used Java... in short, I have a steep learning curve littered with rocks
> and nails.   I also don't know whether it's a good thing that I have
> long experience with Python and C :-P
>
> In any case, as a first project, I'm trying to add PostgreSQL support to
> Clogger (http://github.com/Ejhfast/Clogger/tree/master) and I've managed
> to get it working.  
>
> *But*, the number of changes involved suggest that I should put the
> existing MySQL code and the new PostgreSQL code into a separate files
> and pull in the correct one at runtime based on a configuration
> variable.   This is where I'm choking.
>
> I've created a global variable *db-adapter* in setup.clj and would like
> change
>
> http://github.com/Ejhfast/Clogger/blob/dce291524ab76796c781f720020707...
>
> to selectively :use (or :import or whatever) mysql.clj or postgresql.clj
> based upon the value of *db-adapter*.   In turn, mysql.clj and
> postgresql.clj will contain custom versions of the "db" and
> "create-blog" code from database.clj (this leads to a second issue, but
> I'll save that for later).
>
> What I've tried (no laughing!) is this bit of code:
>
> (ns site.database
>   (:use [compojure])
>   (:use [clojure.contrib.sql])
>   (:use [site.setup])
>
>   (if (= *db-adapter* "mysql")                                                
>                                                                               
>           
>     (:use [site.adapters.mysql :as adapter]))                                 
>                                                                               
>          
>   (if (= *db-adapter* "postgresql")                                           
>                                                                               
>          
>     (:use [site.adapters.postgresql :as adapter])))
>
> But this throws an error:
>
>    java.lang.Exception: No such var: clojure.core/if (database.clj:1)
>
> In any case, this code smells funny, even if it were to work.  It seems
> I should be able to somehow build a string such as (str "site.adapters."
> *db-adapter*) and use that instead (or something else equally concise).
>
> And of course, this isn't my only problem.   But I'll keep it to one
> issue at a time.
>
> Regards,
> Cliff
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to