In Clojure 1.4 what is the use of refer within require?

What advantage does using :refer in :require have over using :only in :use? Are the following synonymous?

(ns so.example (:use [my.lib :only [function]]))

and

(ns so.example (:require [my.lib :refer [function]]))

Main idea of adding :refer to :require is to get rid completely of :use, leaving only one operator to load other packages. You can emulate existing :use with (:require [my.lib :refer :all])...


yes, they are equivalent,

:refer and :require are the basic operations required to build namespaces. :use is more convienient

  • :require causes classes to be loaded
  • :refer adds things to the name space which is really just a map (actually a couple of maps)
  • :use is :refer + :require

as much is it may look like it, there really is no magic to namespaces

if you make a namespace like this

(ns so.example (:use my.lib))

the equivalent with :require would be:

(ns so.example (:require [my.lib :refer [function1 function2 function3 
                                         list every function in example 
                                         here and remember to keep it 
                                         up to date ]]))

As of the 1.4.0 release, there's no longer a good reason to use use. Use require :refer instead. From the Clojure 1.4.0 changelog: "require can now take a :refer option. :refer takes a list of symbols to refer from the namespace or :all to bring in all public vars." (from https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html)