如果我加载一个文件(ns my-namespace),为什么不切换我当前的命名空间? [英] If I load a file with (ns my-namespace) in it, why doesn't it switch my current namepace?

查看:146
本文介绍了如果我加载一个文件(ns my-namespace),为什么不切换我当前的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的档案

(ns boston.core)

如果来自REPL的I (加载boston / core) c $ c> * ns * 不会更改为 boston ,但仍保留用户。为什么是这样?

If I (load "boston/core") from the REPL, however, my *ns* doesn't change to boston but remains user. Why is this?

推荐答案

这是因为load只是加载指定的文件(到boston.core命名空间,文件的顶部)。它不会对REPL中的当前命名空间执行任何操作。

This is because load just loads the specified file (into the boston.core namespace, as specified at the top of the file). It doesn't do anything to the current namespace in the REPL.

如果您还想在REPL中切换命名空间以使用刚刚加载的任何内容,则需要执行例如:

If you also want to switch namespace in the REPL to use whatever has just been loaded you need to do something like:

(load "boston/core")
(ns boston.core)

请注意,boston / core有一个斜杠,因为它指的是一个文件资源,而命名空间本身使用一个点作为分隔符。

Note that "boston/core" has a slash because it refers to a file resource, whereas namespaces themselves use a dot as separators.

这篇关于如果我加载一个文件(ns my-namespace),为什么不切换我当前的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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