Clojure 是否有类似于 ~/.clisprc.lisp 的配置文件?

发布于 2024-10-20 17:45:43 字数 135 浏览 3 评论 0原文

在我的平台上,我需要添加 (set! *compile-path* (str *compile-path* ":.")) 以便 (compile)找到我的脚本。我不想每次要编译某些东西时都必须输入该内容。

On my platform, I need to add (set! *compile-path* (str *compile-path* ":.")) in order for (compile) to find my scripts. I'd prefer not to have to type that every time I want to compile something.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

明明#如月 2024-10-27 17:45:43

在 Clojure 中设置“编译路径”的最简单方法是使用构建工具,例如 Leiningen 或 < a href="https://github.com/ninjudd/cake" rel="nofollow">Cake 来管理您的项目。使用这些工具,您可以获得惯用的项目结构,所有源代码自动位于编译/类路径上,以及用于处理依赖项检索、运行单元测试和构建项目的良好命令行工具。

以下是 Leiningen 定义的一些基本命令行任务,因此您可以在任何项目中使用它们:

classpath   Show the classpath of the current project.
clean       Remove compiled artifacts and jars from project.
compile     Compile Clojure source into .class files.
deps        Download all dependencies and place them in the :library-path.
help        Display a list of tasks or help for a given task.
install     Install the current project or download the project specified.
interactive Enter interactive shell for calling tasks without relaunching JVM.
jar         Package up all the project's files into a jar file.
javac       Compile Java source files.
new         Create a new project skeleton.
plugin      Manage user-level plugins.
pom         Write a pom.xml file to disk for Maven interop.
repl        Start a repl session either with the current project or standalone.
run         Run a -main function with optional command-line arguments.
swank       Launch swank server for Emacs to connect.
test        Run the project's tests.
test!       Run a project's tests after cleaning and fetching dependencies.
uberjar     Package up all the project's files and dependencies into a jar file.

因此,您可以通过运行 lein new <项目名称> 来启动一个新项目,这会生成一个Clojure 项目的标准目录结构。编写完代码后,您可以运行 leincompile 来简单编译 Clojure 源代码,也可以直接转到 leinjar 将代码打包为 Jar 文件。对于包含 Clojure 语言以及运行程序所需的所有依赖项的可执行 jar,请改用 lein uberjar。

如果您不使用这些工具,则需要手动管理类路径,以包括存储依赖项 jar 的位置以及源代码所在的位置。我强烈建议使用上述构建工具之一。

The easiest way to handle setting your "compile path" in Clojure is to use a build tool like Leiningen or Cake to manage your project. Using these tools, you get an idiomatic project structure, all your source code automatically on the compile/class path, and nice command-line tools to handle dependency retrieval, running unit tests and building your projects.

Here are some of the basic command-line tasks defined by Leiningen, and thus available to you in any project:

classpath   Show the classpath of the current project.
clean       Remove compiled artifacts and jars from project.
compile     Compile Clojure source into .class files.
deps        Download all dependencies and place them in the :library-path.
help        Display a list of tasks or help for a given task.
install     Install the current project or download the project specified.
interactive Enter interactive shell for calling tasks without relaunching JVM.
jar         Package up all the project's files into a jar file.
javac       Compile Java source files.
new         Create a new project skeleton.
plugin      Manage user-level plugins.
pom         Write a pom.xml file to disk for Maven interop.
repl        Start a repl session either with the current project or standalone.
run         Run a -main function with optional command-line arguments.
swank       Launch swank server for Emacs to connect.
test        Run the project's tests.
test!       Run a project's tests after cleaning and fetching dependencies.
uberjar     Package up all the project's files and dependencies into a jar file.

So you start a new project by running lein new <name of project>, which generates a standard directory structure for a Clojure project. After you've written your code, you can run lein compile to simply compile your Clojure source, or you can go right to lein jar to package your code as a Jar file. For an executable jar that includes the Clojure language and all dependencies necessary to run your program, use lein uberjar instead.

If you don't use these tools, then you need to manage the classpath manually, to include where you store your dependency jars and where your source code lives. I highly recommend using one of the above-mentioned build tools.

淡淡の花香 2024-10-27 17:45:43

您可以在运行 Clojure 时指定 -i 以使其在启动时评估文件。
下面是我用来运行 Clojure 的脚本作为示例:

#!/bin/bash

# GUI mode
if [ "$1" != "--no-fork" ]; then
    gnome-terminal -t Clojure -x $0 --no-fork $* &
    exit
fi

shift

breakchars="(){}[],^%$#@\"\";:''|\\"
if [ -f project.clj ]; then
    lein repl
else
    rlwrap --remember -c -b "$breakchars" \
           java -Djava.ext.dirs=$HOME/.clojure clojure.main \
           -i $HOME/.clojurerc --repl
fi

You can specify -i when running Clojure to have it evaluate a file when starting up.
Below is the script I use to run Clojure as an example:

#!/bin/bash

# GUI mode
if [ "$1" != "--no-fork" ]; then
    gnome-terminal -t Clojure -x $0 --no-fork $* &
    exit
fi

shift

breakchars="(){}[],^%$#@\"\";:''|\\"
if [ -f project.clj ]; then
    lein repl
else
    rlwrap --remember -c -b "$breakchars" \
           java -Djava.ext.dirs=$HOME/.clojure clojure.main \
           -i $HOME/.clojurerc --repl
fi
朦胧时间 2024-10-27 17:45:43

Leiningen 每次启动时都会加载 ~/.lein/init.clj。此外,您可以将 :repl-init 键添加到 project.clj 文件中,以便在每个 repl 中加载该命名空间。 Clojure 实际上并不意味着在没有任何支持工具的情况下独立使用,因此您自己调用 (compile [...]) 几乎从来都不是正确的答案。

Leiningen will load ~/.lein/init.clj every time it launches. In addition, you can add a :repl-init key to your project.clj files to have that namespace loaded in each repl. Clojure is really not meant to be used standalone without any supporting tools, so calling (compile [...]) on your own is almost never the right answer.

酒几许 2024-10-27 17:45:43

在 Clojure 中,这是在 Java 级别(类路径等)进行管理,而不是使用 .rc 文件。当我第一次开始使用 Clojure 编程时,我有一个可以运行的 bash 脚本,但现在我使用 Leiningen。

In Clojure this is managed at the Java level (classpath etc) rather than having a .rc file. When I first started programming in Clojure I had a bash script that I would run, but now I use Leiningen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文