将名称空间导入到lein repl并引用它 [英] Importing a namespace into the lein repl and refer to it

查看:109
本文介绍了将名称空间导入到lein repl并引用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在档案中,我可以这样做:

In a file I can do this:

(:require [clojurewerkz.neocons.rest :as nr])

如何将它导入到repl并仍然能够引用它'nr'?

how can I import this into the repl and still be able to refer to it by 'nr'?

感谢

推荐答案

李的回答是对的,当然,但为什么你需要报价?向量 [...] 被计算,内部的值也是,这里 clojurewerkz.neocons.rest nr 被视为变量,它是未绑定的(你有一个错误消息,不是吗?您也可以选择引用符号:

Lee's answer is right, of course, but why do you need to quote? The vector [...] is evaluated and the values inside too, and here both clojurewerkz.neocons.rest and nr are treated as variables, which are unbound (you do have an error message, don't you?). You can also choose to quote the symbols:

(require ['clojurewerkz.neocons.rest :as 'nr])

这也意味着你可以 require 如果你传递一个变量。

This also means that you could require namespaces dynamically, if you pass a variable.

但是,为什么你不需要引用一个文件?我想这是因为在您的文件中找到的(require ...)被包含在 ns 宏中,因此,不对表单进行评估。请参阅 require

But then, why don't you need to quote inside a file? I suppose that this is because the (require ... ) found in your file is enclosed in an ns macro, and as such, the forms are not evaluated. See require.

这篇关于将名称空间导入到lein repl并引用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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