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 8759227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:44:56+00:00 2026-06-13T14:44:56+00:00

I have some private functions in one namespace that I would like to include

  • 0

I have some private functions in one namespace that I would like to include in a second namespace. e.g.

(ns one)

(defn ^:private foo 
  "A docstring"
  [x] (* x 2))

And the second namespace needs to create an alias to this:

(ns two)

(def foo ???)

(foo 3)   ;; should work as if the function in namespace one was called
=> 6

Ideally I’d like to preserve the docstring so I don’t have to maintain it in two places. Also I’d like to have the option to either use the same name or a different name.

The reason for this requirement is as follows: the functionality is needed/used in namespace one. one is a dependency of two, and since we can’t have circular dependencies it won’t work to define foo within two itself. two is the public API, so foo needs to be publicly part of the two namespace.

What’s the best way to achieve this?

  • 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-06-13T14:44:58+00:00Added an answer on June 13, 2026 at 2:44 pm

    How about this:

    (ns one)
    
    (defn- foo 
      "A docstring"
      [x] (* x 2))
    
    (ns two)
    
    (def foo-alias #'one/foo)
    (alter-meta! #'foo-alias merge (select-keys (meta #'one/foo) [:doc :arglists]))
    

    The trick is to not resolve the symbol ‘one/foo, hence avoiding to trigger the private flag on its metadata. Then after aliasing foo in your second namespace, you simply cherry pick the metadata you want to keep from the previous definition.

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

Sidebar

Related Questions

I have some debugging functions that I would like to refactor, but seeing as
I have a JQuery control which has some private methods. I would like to
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
Suppose I have a class Foo , with a private variable bar_ containing some
I have a class that is getting called and for some reason one of
If I have a private variable that I want to have some internal validation
We have some code that looks like this: class Serializer { public: template<class Type>
I have to display some private Youtube videos in my blog. I cannot embed
I have some CRUD routing: /news/{page} // public /news/new // private /news/{slug}/show //public /news/{slug}/edit
I have some files stored at amazon. all in private mode, and since I

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.