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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:46:48+00:00 2026-05-15T23:46:48+00:00

I am writing a Clojure library and I am wondering what is the best

  • 0

I am writing a Clojure library and I am wondering what is the best practice for setting configuration parameters of a library.

Many libraries (like those in clojure-contrib) use global level parameter like *buffer-size* which the user can set by calling set! on them. But this does not seems to be best way to me as it creates a global state and there are chances of name collision.

The other way is to pass the parameters in every function call that is dependent on them. If there are many parameters then a map of them can be used instead of passing individual ones.

As an example, let’s say that I am writing a cache library.

Using the first approach I have global parameters like *cache-size*, *expiry-time*, *cache-dir* etc. The user set!s these (or not and let them be default) and calls functions like (set-in-cache id obj) and (get-from-cache id).

Using the second approach, the user first create a map of parameters and passes it to every call

(def cache-parameters {:cache-size 1000 
                       :expiry-time: 1440 
                       :cache-dir "c:\\cache"})
(set-in-cache cache-parameters id obj)
(get-from-cache cache-parameters id)

So which way is the preferred way in Clojure and why?

  • 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-15T23:46:49+00:00Added an answer on May 15, 2026 at 11:46 pm

    Actually you cannot set! things like c.c.io‘s *buffer-size* unless you install a thread-local binding for them with binding, with-bindings etc. There’s just a handful of Vars for which thread-local bindings are installed by lower level Clojure machinery, such as *warn-on-reflection* and *read-eval*, making them set!-able at top-level; user-defined Vars are not set!-able at top-level. The root binding of a Var can be changed with e.g. alter-var-root, intern, def, .bindRoot …, but this should be used sparingly.

    As for the rebindable Vars vs. explicit parameters part of the question: going with explicit parameters is almost always ok and usually preferable, just because of the increased maintainability of functions which clearly display all pieces of data they depend on. That being said, if some piece of configuration is likely to be set once, then used by virtually every function call within the app / library ever after, it might make for saner code to define an earmuffed Var, document it well and put the config in it (and this might be one of the rare cases where changing a Var’s root binding outside of the form which defines might be ok).

    To summarise, use your best judgement, if unsure — err on the side of explicit parameter passing.

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

Sidebar

Related Questions

I'm writing a Clojure wrapper for the Braintree Java library to provide a more
I'm creating a library that includes both Clojure and Java code, and would like
I'm writing a simple photo library app in Clojure. I have a library map
I've noticed that some libraries such as clojure-twitter use special vars (the ones intended
I'm writing a little parser in clojure for learning purpose. basically is a TSV
I'm writing a simple IRC bot to try to learn more about Clojure, using
I'm writing a Clojure implementation of this coding challenge , attempting to find the
I'm writing some Clojure code that depends upon a number of constants. They will
I am writing a Desktop GUI application in Clojure using Java Swing. Normally when
In clojure, I can destructure a map like this: (let [{:keys [key1 key2]} {:key1

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.