tags:

views:

53

answers:

1

When I require libraries from the ns form I get :

test> (ns test (:require '(clojure.contrib [logging :as log] [sql :as sql]) ))
lib names inside prefix lists must not contain periods
[Thrown class java.lang.Exception]

When I use the require function it works as expected.

test> (require '(clojure.contrib [logging :as log] [sql :as sql]) )
nil

The documentation for ns refers to the documentation of the require function but as they behave differently this is a bit confusing.

+5  A: 

The ns form is a macro, and so it doesn't require that you use ' to quote the provided seq.

An example from the Clojure docs:

(ns foo.bar
    (:refer-clojure :exclude [ancestors printf])
    (:require (clojure.contrib sql sql.tests))
    (:use (my.lib this that))
    (:import (java.util Date Timer Random)
       (java.sql Connection Statement)))
levand
Ouch, bitten again by this 'feature'... Thanks!
Peter Tillemans
Yeah, it's not very consistent. The general guideline, though, is that it's pretty much always better to use ns instead of import, require, etc. directly. You should probably think of the individual forms as low-level primitives, and use ns exclusively.
levand
What surprises me is that the macros are not supporting the quoted form for consistency. I've got to dig into this one evening to figure out why this is.
Peter Tillemans