为什么 ns 形式的 require 与 require 函数的行为不同 [英] Why does require in the ns form behave different from the require function

查看:19
本文介绍了为什么 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆