What's the correct way of providing a default value for *print-length* in profiles.clj?

余生颓废 提交于 2021-01-22 13:37:22

问题


For those that do not know what *print-length* stands for:

If you (set! *print-length* 200), and you evaluate (range) in a REPL, which normally causes an infinite list of numbers to get printed, only the first 200 numbers will get printed.

I'm trying to set this as a default for all my REPLs in profiles.clj. Right now I got this, but it doesn't work:

{:user {:plugins [[lein-swank "1.4.4"]
                  [lein-catnip "0.5.0"]]
        :repl-options {*print-length* 200}} 
 :dev {:dependencies [[clj-ns-browser "1.2.0"]
                      [org.clojure/tools.trace "0.7.5"]]}}

What's wrong with this?

Update. Tnx Michal for answering this. My fixed profiles.clj now looks like this. Note that it only works inside a project.

{:user {:plugins [[lein-swank "1.4.4"]
                  [lein-catnip "0.5.0"]]
        :repl-options {:init (set! *print-length* 200)}} 
 :dev {:dependencies [[clj-ns-browser "1.2.0"]
                      [org.clojure/tools.trace "0.7.5"]]}}

回答1:


:repl-options needs to be a map of options supported by Leiningen's repl task; anything else will be ignored. *print-length* is not a valid option (and neither is nil; I'd have to check to be sure if the keys are evaluated here, but this won't work either way).

Instead you should use something like

:repl-options {:init (set! *print-length* 200)}

See sample.project.clj in the root of Leiningen's repository for a description of the available options (including :init).




回答2:


This is now also supported in project.clj:

:global-vars {*print-length* 20}


来源:https://stackoverflow.com/questions/14664486/whats-the-correct-way-of-providing-a-default-value-for-print-length-in-profil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!