You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在deps.edn中设置*print-length*默认值(替代Leiningen的project.clj)

How to set a default *print-length* in deps.edn?

Great question! Unlike Leiningen's project.clj which had straightforward profile-based options for setting dynamic vars like *print-length*, deps.edn requires a bit more explicit setup—but there are several clean, reliable approaches to get this working. Here are the most common methods:

1. Use a user.clj namespace (simplest approach)

Clojure automatically loads a user namespace from your classpath when starting a REPL, making this the easiest way to set default values for dynamic vars.

  • Create a src/user.clj file (or add to an existing one) with:
    (ns user)
    ;; Set your desired default print length
    (set! *print-length* 10)
    
  • Since src/ is included in the default classpath for deps.edn projects, just start your REPL with clj—the user namespace will load automatically, and *print-length* will be set to your chosen value.

2. Inject initialization code via JVM options

You can pass a Clojure expression directly to the JVM to execute on startup using the clojure.main.init system property. This works well if you want to tie the setting to a specific alias.

Add this to your deps.edn:

{:aliases
 {:dev {:jvm-opts ["-Dclojure.main.init='(set! *print-length* 10)'"]}}}

Then start your REPL with:

clj -A:dev

Note: If you're using Windows Command Prompt, you may need to adjust the quoting (e.g., use double quotes around the entire JVM option and escape inner quotes).

3. Load a dedicated initialization namespace

If you prefer to keep your setup organized in a separate namespace (instead of user.clj), you can create an init namespace and load it on startup.

  • First, create src/dev/init.clj:
    (ns dev.init)
    (set! *print-length* 10)
    ;; Add other dev-specific settings here if needed
    
  • Update your deps.edn to include the src/dev path and load the namespace on startup:
    {:aliases
     {:dev {:extra-paths ["src/dev"]
            :main-opts ["-e" "(do (require 'dev.init) (clojure.main/repl))"]}}}
    
  • Start your REPL with clj -A:dev—this will load the dev.init namespace (setting *print-length*) and then launch the REPL.

All of these methods will ensure *print-length* is set to your preferred default every time you start your Clojure REPL via deps.edn. The user.clj approach is generally the most low-friction for most projects!

内容的提问来源于stack exchange,提问作者Mert Nuhoglu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:54:31