为什么ns中的require要求与require函数不同 [英] Why does require in the ns form behave different from the require function
本文介绍了为什么ns中的require要求与require函数不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我需要ns表单的库时,我得到:
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]
当我使用require函数时,它按预期工作。
When I use the require function it works as expected.
test> (require '(clojure.contrib [logging :as log] [sql :as sql]) )
nil
ns的文档指的是require函数的文档,但是它们的行为不同,这有点混乱。
The documentation for ns refers to the documentation of the require function but as they behave differently this is a bit confusing.
推荐答案
ns
表单是一个宏,因此不需要使用'引用提供的seq。
The ns
form is a macro, and so it doesn't require that you use ' to quote the provided seq.
Clojure文档中的示例:
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)))
这篇关于为什么ns中的require要求与require函数不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文