10

The source for lazy-xml has the following:

(:use [clojure.xml :as xml :only []]
      [clojure.contrib.seq :only [fill-queue]])

What is the purpose of using clojure.xml but listing nothing for the :only arguments?

Andrew
  • 7,286
  • 3
  • 28
  • 38

1 Answers1

12

Notice the :as xml which when combined with the :only [] seems to make that line equivalent to (:require [clojure.xml :as xml]). That style might be useful if you want to copy some vars into the local namespace (i.e., a non-empty :only), but allow the rest of that namespace to be explicitly aliased via :as. Since that's not what he's doing, it really should just be a :require.

Alex Taggart
  • 7,805
  • 28
  • 31
  • 3
    Probably the person writing this code has a bunch of `:use` declarations already and didn't want to write a separate `:require` clause. Not a recommended decision IMO, but if he only has one namespace that he's using in this way it would save him a couple characters. – amalloy Oct 16 '11 at 23:52
  • Code smell? I wonder why the language designer(s) did not opt to have a *single* (combined) use/require form. – Sridhar Ratnakumar Oct 17 '11 at 17:09
  • @SridharRatnakumar What. That "I wonder" question doesn't make sense. The `ns` macro is a combined use/require form, and you have to specify somehow which part you want interpreted as a `use`, and which as a `require`. He couldn't just magically guess. – amalloy Oct 17 '11 at 20:32
  • @amalloy - My question was more like "why do we *need* a separate `use` and `require` functionality in the first place"? – Sridhar Ratnakumar Oct 19 '11 at 17:08
  • 1
    I did a little research myself and discovered this new syntax that could unify use/require: https://github.com/stuartsierra/need – Sridhar Ratnakumar Oct 19 '11 at 17:19
  • Note that as of Clojure 1.4, require can take a :refer option: https://github.com/clojure/clojure/blob/master/changes.md#213-require-can-take-a-refer-option – duelin markers Mar 31 '13 at 14:29