Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does require in the ns form behave different from the require function

Tags:

clojure

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.

like image 306
Peter Tillemans Avatar asked Sep 15 '10 16:09

Peter Tillemans


1 Answers

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)))
like image 150
levand Avatar answered Oct 13 '22 00:10

levand