user.clj和init.clj无法工作?

7
这是我的问题: 每次打开新的repl时,我需要运行一些代码。在谷歌上搜索后,我发现可以使用文件init.clj或者(使用Leiningen)user.clj来实现。
这是我需要运行的代码:
(set! *print-length* 103)  
(println "hello")
(println *print-length*)

这是两个文件的结果:

[~/project]$ lein repl
hello    <- this is the println, so the file is excecuted  
103      <- this is the println of *print-length* apparently change  
REPL started; server listening on localhost port 20875  
user=> *print-length*  
nil      <- but the val of *print-length* don't change

我需要做些什么或者我有错误吗?

感谢所有人!

2个回答

4

4

(alter-var-root#'* print-length*(恒定103))~/user.clj 对我有用。

据我所知,set!binding 的动态范围之外无法使用。


你知道如何使用函数“use”来始终使用ns吗?我有这行代码(use '[clojure.contrib.string :exclude [repeat butlast drop partition get reverse take]])但它不起作用。 - patz
@patz 请尝试提出一个新问题 :) - wrongusername

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接