Re: Help organizing code and namespaces

2011-06-20 Thread Jonathan Fischer Friberg
Create a new namespace+file my.server where the *server* resides, then let
my.query and my.update use my.server.

Jonathan

On Sat, Jun 18, 2011 at 3:52 PM, Matt Mitchell  wrote:

> Hi,
>
> I have 3 namespaces, each with functions that relate to the name of the ns:
>
> core -- contains config and *server* var
> query  -- contains fn's related to querying
> update -- contains update/delete fn's
>
> I want to be able to "use" my core ns in my application, and call all of
> the public fn's in core, query and update without going through the query
> and update ns aliases. This would be as simple as specifying "use" in the
> core ns when defining the namespace.
>
> The problem is that the query and update ns's need to access a var called
> *server* in the core ns. The *server* var is set using binding like so:
>
> (use 'my.core)
> (with-server :whatever-sever-name
>   (delete-by-id "xyz"))
>
> delete-by-id is an fn in the update namespace, and looks something like:
>
> (defn delete-by-id [id] (*server*/delete-by-id id))
>
> The problem is *server* belongs to core, so that doesn't work. If I pull in
> core to the update ns, I get a circular reference error.
>
> My question is, how can I keep my code separated as it is, but have it so I
> use core, and automatically bring all the fn's in to the same scope, all
> while sharing the core/*server* var? I could easily push all the fn's in the
> same ns, but that seems messy.
>
> Thanks,
> Matt
>
> --
> 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 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

Re: Help organizing code and namespaces

2011-06-19 Thread Benjamin Teuber
Hi,

this should be what you need:
http://stackoverflow.com/questions/4690758/splitting-a-clojure-namespace-over-multiple-files

On Jun 18, 3:52 pm, Matt Mitchell  wrote:
> Hi,
>
> I have 3 namespaces, each with functions that relate to the name of the ns:
>
> core -- contains config and *server* var
> query  -- contains fn's related to querying
> update -- contains update/delete fn's
>
> I want to be able to "use" my core ns in my application, and call all of the
> public fn's in core, query and update without going through the query and
> update ns aliases. This would be as simple as specifying "use" in the core
> ns when defining the namespace.
>
> The problem is that the query and update ns's need to access a var called
> *server* in the core ns. The *server* var is set using binding like so:
>
> (use 'my.core)
> (with-server :whatever-sever-name
>   (delete-by-id "xyz"))
>
> delete-by-id is an fn in the update namespace, and looks something like:
>
> (defn delete-by-id [id] (*server*/delete-by-id id))
>
> The problem is *server* belongs to core, so that doesn't work. If I pull in
> core to the update ns, I get a circular reference error.
>
> My question is, how can I keep my code separated as it is, but have it so I
> use core, and automatically bring all the fn's in to the same scope, all
> while sharing the core/*server* var? I could easily push all the fn's in the
> same ns, but that seems messy.
>
> Thanks,
> Matt

-- 
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


Help organizing code and namespaces

2011-06-18 Thread Matt Mitchell
Hi,

I have 3 namespaces, each with functions that relate to the name of the ns:

core -- contains config and *server* var
query  -- contains fn's related to querying
update -- contains update/delete fn's

I want to be able to "use" my core ns in my application, and call all of the 
public fn's in core, query and update without going through the query and 
update ns aliases. This would be as simple as specifying "use" in the core 
ns when defining the namespace.

The problem is that the query and update ns's need to access a var called 
*server* in the core ns. The *server* var is set using binding like so:

(use 'my.core)
(with-server :whatever-sever-name
  (delete-by-id "xyz"))

delete-by-id is an fn in the update namespace, and looks something like:

(defn delete-by-id [id] (*server*/delete-by-id id))

The problem is *server* belongs to core, so that doesn't work. If I pull in 
core to the update ns, I get a circular reference error.

My question is, how can I keep my code separated as it is, but have it so I 
use core, and automatically bring all the fn's in to the same scope, all 
while sharing the core/*server* var? I could easily push all the fn's in the 
same ns, but that seems messy.

Thanks,
Matt

-- 
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