Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...