FAQ

[Clojure] Suggestion needed for namespace management in modular clojure app

Vivek Khurana
Oct 7, 2011 at 1:37 pm
Hi!

I am working on a clojure app which needs to be modular. The module
need to be pluggable. While I have figure out the pluggable part, I am
facing issues with managing namespaces. I would prefer to have a
modules directory where each module will create a sub directory and
all files in the module sub directory expose a single namespace. The
problem is even with AOT compile I am not able to achieve this. What I
need is if the path of module subdirectory is xyz/modules/accounts teh
namespace should be xyz.modules.accounts . How do I achieve this ?
When ever I try to use AOT I get errors.

Also, is there a better way to manage namespaces in modular
applications. I do not want the developers of modules to struggle with
managing files and namespaces.

regards
Vivek

--
The hidden harmony is better than the obvious!!

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
reply

Search Discussions

3 responses

  • Stephen Compall at Oct 9, 2011 at 3:18 am

    On Fri, 2011-10-07 at 19:07 +0530, Vivek Khurana wrote:
    I would prefer to have a
    modules directory where each module will create a sub directory and
    all files in the module sub directory expose a single namespace.
    So it sounds like you intend for module writers to be writing Clojure,
    but want to replace the standard way namespaces are done in Clojure
    (i.e. ns form at top of file).
    When ever I try to use AOT I get errors.
    You should avoid AOT for this; indeed, perhaps modules shouldn't even go
    in the src/ directory, assuming you are using Leiningen or something
    with similar structure.
    Also, is there a better way to manage namespaces in modular
    applications. I do not want the developers of modules to struggle with
    managing files and namespaces.
    If you wish to replace the standard Clojure conventions for managing
    files and namespaces, as codified by `require' and its ilk, these items
    will help you on your adventure:

    clojure.core/*ns*
    A clojure.lang.Namespace object representing the current namespace.

    clojure.core/load
    ([& paths])
    Loads Clojure code from resources in classpath. <snip>

    clojure.core/load-file
    ([name])
    Sequentially read and evaluate the set of forms contained in the file.

    You could bind `*ns*' to a namespace you construct yourself while
    loading the files that make up a module, in a guaranteed order of
    course.

    I'm sure you'll have many adventures on the way to a robust
    implementation of this idea. One more hint before you embark: defend
    yourself from parallel loading.

    --
    Stephen Compall
    ^aCollection allSatisfy: [:each|aCondition]: less is better

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Vivek Khurana at Oct 11, 2011 at 3:17 am

    On Sun, Oct 9, 2011 at 8:48 AM, Stephen Compall wrote:
    On Fri, 2011-10-07 at 19:07 +0530, Vivek Khurana wrote:
    I would prefer to have a
    modules directory where each module will create a sub directory and
    all files in the module sub directory expose a single namespace.
    So it sounds like you intend for module writers to be writing Clojure,
    but want to replace the standard way namespaces are done in Clojure
    (i.e. ns form at top of file).
    Not just clojure. Solution for clojure only code is simple. The
    application is a framework, which will expose some API and modules
    consuming the API, can be written in any JVM language. It is known
    that all modules will run from same instance of JVM. The issue is that
    I should be able to distinguish between the modules written by core
    team and modules written by others and cannot figure out the correct
    way to manage namespaces in this situation.
    When ever I try to use AOT I get errors.
    You should avoid AOT for this; indeed, perhaps modules shouldn't even go
    in the src/ directory, assuming you are using Leiningen or something
    with similar structure.
    Yes I am using Leiningen. Do you suggest I should host the modules
    out side the src ? Wont that create a classpath havoc ? Secondly, in
    case the modules are outside src, how will they compile ? Do I need to
    make any changes to Leingen configuration ?
    Also, is there a better way to manage namespaces in modular
    applications. I do not want the developers of modules to struggle with
    managing files and namespaces.
    If you wish to replace the standard Clojure conventions for managing
    files and namespaces, as codified by `require' and its ilk, these items
    will help you on your adventure:

    clojure.core/*ns*
    A clojure.lang.Namespace object representing the current namespace.

    clojure.core/load
    ([& paths])
    Loads Clojure code from resources in classpath. <snip>

    clojure.core/load-file
    ([name])
    Sequentially read and evaluate the set of forms contained in the file.

    You could bind `*ns*' to a namespace you construct yourself while
    loading the files that make up a module, in a guaranteed order of
    course.
    It might be difficult to guarantee the order when number of modules increase...

    regards
    Vivek
    --
    The hidden harmony is better than the obvious!!

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
  • Stuart Sierra at Oct 11, 2011 at 12:30 pm

    Not just clojure. Solution for clojure only code is
    simple. The application is a framework, which will expose
    some API and modules consuming the API, can be written in
    any JVM language. It is known that all modules will run
    from same instance of JVM.
    Sounds like you may need something more elaborate than what Clojure
    namespaces were intended provide. This type of framework is a well-covered
    area on the JVM. Consider investigating JVM modularity systems like OSGi.

    -Stuart Sierra
    clojure.com

    --
    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+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en

Related Discussions

Discussion Navigation
viewthread | post