为什么我在新的 slime 会话中看不到我的宏创建的函数? (克洛朱尔)
在我的 clojure 代码中,我有一些通过调用自定义宏创建的函数。通常,宏会采用某种数据结构并从中创建方法。
这是一个人为的示例:
(create-function {:name "view-data" ...})
它将创建一个名为 view-data
的新函数。 (我的数据库查询是数据驱动的,因此我可以创建一个具有指示性名称的函数来调用特定查询)
我的问题是,当我运行 mvn clojure:swank 目标并连接到 slime 时来自 emacs 的会话这些函数不可见。我必须访问该文件并使用 Cc Ck
自行编译它才能创建函数。
maven 输出表明文件本身编译良好,但 slime 会话不知道这些功能。
任何想法为什么会发生这种情况?
In my clojure code, I have a few functions which are created with calls to custom macros. Typically, the macros would take a data structure of some sort and create a method from it.
This is a contrived example:
(create-function {:name "view-data" ...})
which would create a new function called view-data
. (My database queries are data-driven, so I can create a function with an indicative name that calls a specific query)
My problem is that when I run the mvn clojure:swank
target and connect to the slime session from emacs these functions aren't visible. I have to visit the file and compile it myself with C-c C-k
for the functions to be created.
The maven output suggests that the files themselves compile fine, but the slime session doesn't know about the functions.
Any ideas why this might be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的项目中有一个文件,它
需要
所有的命名空间,这使得 repl 中每个位置的所有函数都可用。也许有一种更优雅的方法可以做到这一点,但这个技巧对我来说非常可靠。I have a file in my project that
require
s all the namespaces which makes all the functions from every where available in the repl. perhaps there is a more slime-elegant way of doing this, but this hack has been very reliable for me.请注意,在 clojure 中,编译和加载是单独的步骤。你可以生成所有你喜欢的类文件,但如果不加载它们,也不会影响运行过程。
我对 clojure:swank for maven 不太了解,但在我看来,像 leiningen 一样,swank 目标只会为您的项目设置类路径并加载 swank 代码,但不会加载项目中的任何代码。因此,在此之后您仍然需要以某种方式加载代码(例如,从 Emacs/SLIME、使用其他目标/插件或从 REPL)。
Note that in clojure, compiling and loading are separate steps. You can generate all the class files you like, but if they're not loaded, it won't affect the running process.
I don't know enough about clojure:swank for maven, but it sounds to me that, like leiningen, the swank target will only set up the classpath for your project and load the swank code but not any of the code in your project. So you will still have load load your code in some way after that (for instance; from Emacs/SLIME, using some other target/plugin or from the REPL).