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

  • Home
  • SEARCH
  • 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 987489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:29:02+00:00 2026-05-16T05:29:02+00:00

I recently started learning Clojure and I’m having a bit of difficulty wrapping my

  • 0

I recently started learning Clojure and I’m having a bit of difficulty wrapping my head around namespaces. As the creator of Clojure said, newcomers often struggle to get the concept right. I don’t clearly understand the difference between (use ...) and (require ...). For example playing around in the REPL if I say (use 'clojure.contrib.str-utils2) I get warnings about functions in clojure.core namespace being replaced by the ones in clojure.contrib.str-utils2, but that doesn’t happen when I use (require 'clojure.contrib.str-utils2). I’m not sure that I will always want to replace what’s in clojure.core, so can someone point some best practices for importing external stuff and managing namespaces in Clojure?

Oh and also, when should I use :use and :require? Only inside (ns ....)?

Thanks in advance.

  • 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-16T05:29:02+00:00Added an answer on May 16, 2026 at 5:29 am

    The answer lies in the docstrings:

    user> (doc use)
    -------------------------
    clojure.core/use
    ([& args])
      Like 'require, but also refers to each lib's namespace using
      clojure.core/refer. Use :use in the ns macro in preference to calling
      this directly.
    
      'use accepts additional options in libspecs: :exclude, :only, :rename.
      The arguments and semantics for :exclude, :only, and :rename are the same
      as those documented for clojure.core/refer.
    nil
    

    And the long one for require:

    user> (doc require)
    -------------------------
    clojure.core/require
    ([& args])
      Loads libs, skipping any that are already loaded. Each argument is
      either a libspec that identifies a lib, a prefix list that identifies
      multiple libs whose names share a common prefix, or a flag that modifies
      how all the identified libs are loaded. Use :require in the ns macro
      in preference to calling this directly.
    
      Libs
    
      A 'lib' is a named set of resources in classpath whose contents define a
      library of Clojure code. Lib names are symbols and each lib is associated
      with a Clojure namespace and a Java package that share its name. A lib's
      name also locates its root directory within classpath using Java's
      package name to classpath-relative path mapping. All resources in a lib
      should be contained in the directory structure under its root directory.
      All definitions a lib makes should be in its associated namespace.
    
      'require loads a lib by loading its root resource. The root resource path
      is derived from the lib name in the following manner:
      Consider a lib named by the symbol 'x.y.z; it has the root directory
      <classpath>/x/y/, and its root resource is <classpath>/x/y/z.clj. The root
      resource should contain code to create the lib's namespace (usually by using
      the ns macro) and load any additional lib resources.
    
      Libspecs
    
      A libspec is a lib name or a vector containing a lib name followed by
      options expressed as sequential keywords and arguments.
    
      Recognized options: :as
      :as takes a symbol as its argument and makes that symbol an alias to the
        lib's namespace in the current namespace.
    
      Prefix Lists
    
      It's common for Clojure code to depend on several libs whose names have
      the same prefix. When specifying libs, prefix lists can be used to reduce
      repetition. A prefix list contains the shared prefix followed by libspecs
      with the shared prefix removed from the lib names. After removing the
      prefix, the names that remain must not contain any periods.
    
      Flags
    
      A flag is a keyword.
      Recognized flags: :reload, :reload-all, :verbose
      :reload forces loading of all the identified libs even if they are
        already loaded
      :reload-all implies :reload and also forces loading of all libs that the
        identified libs directly or indirectly load via require or use
      :verbose triggers printing information about each load, alias, and refer
    
      Example:
    
      The following would load the libraries clojure.zip and clojure.set
      abbreviated as 's'.
    
      (require '(clojure zip [set :as s]))
    nil
    

    They both do the same thing, but use goes the extra step and creates mappings for the stuff in the require’d namespace in the current namespace. That way, rather than doing some.namespace/name you’re just referring to it as name. While this is convenient sometimes, it’s better to use require or select the individual vars that you want rather than pull in the entire namespace. Otherwise, you could have issues with shadowing (where one var is preferred over another of the same name).

    If you don’t want to use require, but you know what vars you want out of the namespace, you can do this:

    (ns whatever
      (:use [some.namespace :only [vars you want]]))
    

    If you don’t know which vars you’re going to need, or if you need a lot, it’s better to use require. Even when you require, you don’t always have to type the totally qualified name. You can do this:

    (ns whatever
      (:require [some.namespace :as sn]))
    

    and then you can use vars from some.namespace like this: (sn/somefunction arg1 arg2)

    And to answer your last question: try to only use :require and :use inside of (ns …). It’s much cleaner this way. Don’t use and require outside of (ns ..) unless you have a pretty good reason for it.

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

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I recently started reading Paul Grahams 'On Lisp', and learning learning clojure along with
I recently started learning Emacs . I went through the tutorial, read some introductory
I recently started learning Python and I was rather surprised to find a 1000
I recently started learning open source technologies and very soon got frustrated as there
I recently started learning Java and found it very strange that every Java public
I recently started learning DirectX/Windows, and the book I'm learning from had the code
I recently started learning about HttpModules and made my first one. I was wondering
I recently started learning JavaFX. At the moment I can't build any JavaFX project
I have recently started learning F#, and this is the first time I've ever

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.