Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6255923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:27:19+00:00 2026-05-24T14:27:19+00:00

Let’s say I want to build a large clojure library with several components. As

  • 0

Let’s say I want to build a large clojure library with several components. As a developer, I would like to keep many of the components in separate namespaces since many helper functions can have similar names. I don’t necessarily want to make things private since they may have utility outside in extreme cases and the work-arounds behind private is not good. (In other words, I would like to suggest code usage, not completely prevent usage.)

However, I would like the users of the library to operate in a namespace with a union of a subset of many of the functions in each sub library. What is the idiomatic or best way to do this? One solution that comes to my mind is to write a macro that generates :requires and creates a new var mapping by def’ing a given list of var names (see first code example). Are there tradeoffs with this method such as what happens to extending types? Is there a better way (or builtin)?

Macro example (src/mylib/public.clj):

 (ns mylib.public
    (:require [mylib.a :as a])
    (:require [mylib.b :as b]))

 (transfer-to-ns [+ a/+
                  - b/-
                  cat b/cat
                  mapper a/mapper])

Again, to clarify, the end goal would be to have some file in other projects created by users of mylib to be able to make something like (src/someproject/core.clj):

 (ns someproject.core
     (:require [mylib.public :as mylib]))

 (mylib/mapper 'foo 'bar)

@Jeremy Wall, note that your proposed solution does not fullfill my needs. Lets assume the following code exists.

mylib/a.clj:

 (ns mylib.a)

 (defn fa [] :a)

mylib/b.clj:

 (ns mylib.b)

 (defn fb [] :b)

mylib/public.clj:

 (ns mylib.public
     (:use [mylib.a :only [fa]])
     (:use [mylib.b :only [fb]]))

somerandomproject/core.clj: (Assume classpaths are set correctly)

 (ns somerandomproject.core
     (:require [mylib.public :as p])

 ;; somerandomproject.core=> (p/fa)
 ;; CompilerException java.lang.RuntimeException: No such var: p/fa, compiling:     (NO_SOURCE_PATH:3) 
 ;; somerandomproject.core=> (mylib.a/fa)
 ;; :a

If you notice, “using” functions in mylib/public.clj DOES NOT allow public.clj to PROVIDE these vars to the user file somerandomproject/core.clj.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:27:19+00:00Added an answer on May 24, 2026 at 2:27 pm

    You might find it interesting to look at how a library like Compojure or Lamina organizes its “public” api.

    Lamina has “public” namespaces like lamina.api that serve to alias (using Zach’s import-fn from his potemkin library) functions from the “internal” namespaces like lamina.core.pipeline. With a bit of docs, this serves to clearly delineate the public-facing ns’s from the likely-to-change internals. I’ve found the major drawback to this strategy is that the import-fn makes it much more difficult to walk (in emacs) from the use of a function into it’s implementation. Or to know which function to use clojure.repl/source on for example.

    A library like Compojure uses private vars to separate public/private parts of the functions (see compojure.core for example). The major drawback with “private” functions is that you may later find you want to expose them or that it makes testing more complicated. If you control the code base, I don’t find the private aspects to be a big deal. The testing issue is easily worked around by using #’foo.core/my-function to refer to the private function.

    Generally I tend to use something more like Compojure’s style than Lamina’s but it sounds like you’d prefer something more like Lamina.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I need a 3-digit number, so it would be something like: >>>
Let's say I have a drive such as C:\ , and I want to
Let's say I have some content classes like Page, TabGroup, Tab, etc. Certain of
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say that I have classes like this: public class Parent { public int
Let's say I'm creating an OpenGL game in C++ that will have many objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.