当CL程序作为shell脚本调用时如何使用quicklisp?

发布于 2025-01-04 08:35:46 字数 1469 浏览 1 评论 0原文

我目前有一个 Common Lisp 的小程序,我想将其作为 shell 脚本运行。我正在使用 SBCL,并且对此非常满意,因此我更愿意留在这个平台上。 :)

我知道 --script 选项,它可以完美地工作,除了 (ql:quickload) 形式。

我的程序使用 CL-FAD,它通过 ql:quickload 加载(我想我应该提到它是来自 quicklisp 的包加载函数。当脚本运行到评估

(ql:quickload :cl-fad)

表单时,它会出现下一个错误:

package "QL" not found

程序被打包在单个源文件中,该文件具有以下标头:

(defpackage :my-package
  (:use :common-lisp)
  (:export :my-main-method))

它是简单的自动化可执行文件,因此我决定(可能是错误的)不编写任何 ASDF 系统。它导出应该在没有任何参数的情况下运行的单个函数。

对于这个程序,我目前正在尝试编写启动器脚本,这就是我所关注的:

#!/usr/bin/sbcl --script
(load "my-program.lisp")
(in-package :my-package)
(my-main-method)

这三行(不包括 shebang)是我想要自动化的。正如我在文档中读到的,带有这个 shebang 的脚本可以被称为简单的 ./script.lisp,它确实做到了这一点......并出现了前面描述的错误。

我需要在启动器中添加什么才能正确加载 :cl-fad ?文档指出,使用 --script 选项 SBCL 不会加载任何初始化文件,所以我真的需要复制粘贴这些行

#-quicklisp
(let ((quicklisp-init (merge-pathnames "systems/quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

(其中 ql:add-to-init-file 添加到 .sbclrc),到我的启动器脚本? 也许我的程序设置中有一些深层的架构缺陷?

是的,当我在 sbcl 本身的 REPL 中输入尝试自动化的行时,程序按预期运行。

I am currently have a small program in Common Lisp, which I want to run as a shell script. I am using the SBCL and perfectly fine with this so will prefer to stay on this platform. :)

I am aware about the --script option and it works flawlessly except for (ql:quickload) form.

My program uses the CL-FAD, which loads through ql:quickload (I think I should mention that it is package-loading function from quicklisp). When script runs up to evaluating the

(ql:quickload :cl-fad)

form, it breaks with the next error:

package "QL" not found

Program is packed in the single source file, which has following header:

(defpackage :my-package
  (:use :common-lisp)
  (:export :my-main-method))

It is simple automation executable, so I decided (maybe erroneously) not to write any ASDF system. It exports single function which should be run without any arguments.

For this program I am currently trying to write the launcher script, and this is what I am staring at:

#!/usr/bin/sbcl --script
(load "my-program.lisp")
(in-package :my-package)
(my-main-method)

This three lines (not counting the shebang) is what I am want to automate. As I read in documentation, script with this shebang can be called as simple ./script.lisp, and it really does this... with the error described before.

What I need to add in the launcher for :cl-fad to load properly? Documentation states that with --script option SBCL doesn't load any init file, so do I really need to copypaste the lines

#-quicklisp
(let ((quicklisp-init (merge-pathnames "systems/quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

(which ql:add-to-init-file adds to .sbclrc), to my launcher script?
Maybe I have some deep architectural flaw in my program setup?

And yes, when I enter the lines which I try to automate in REPL in the sbcl itself, program runs as expected.

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

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

发布评论

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

评论(2

浅唱ヾ落雨殇 2025-01-11 08:35:46

你做的一切都是正确的。

基本上,在使用 quicklisp 之前,您需要加载它(目前,它未与 SBCL 捆绑在一起,尽管将来可能会发生变化)。有多种方法可以做到这一点。例如,您可以使用 Quicklisp init: 加载 .sbclrc

#!/usr/bin/sbcl --script
(load ".sbclrc")
(load "my-program.lisp")
(in-package :my-package)
(my-main-method)

或者将这些行粘贴到脚本中,就像您所建议的那样。

You are doing everything right.

Basically, before you can use quicklisp, you need to load it (currently, it's not bundled with SBCL, although it may change in the future). There are various ways to do it. For example, you can load your .sbclrc with the quicklisp init:

#!/usr/bin/sbcl --script
(load ".sbclrc")
(load "my-program.lisp")
(in-package :my-package)
(my-main-method)

or just paste those lines in your script, like you have suggested.

指尖上得阳光 2025-01-11 08:35:46

创建核心映像的专用版本是一个不错的选择。您可以:

  1. 在新映像中加载 quicklispsb-ext:save-lisp-and-die。您编写一个名为 qlsbcl 的 shell/bat 脚本,如下所示:

    sbcl --core ; “$@”
    
  2. grab clbuild2 at http://gitorious.org/clbuild2 并运行 clbuild lisp。如果您的 quicklisp 不在公共位置 ~/quicklisp (https://gist.github.com/1485836) 或者如果您使用 ASDF2https://gist.github.com/1621825)。通过这样做,clbuild 使用 quicklispASDF 以及您可以在 conf.lisp 中添加的任何内容创建一个新核心。现在 shebang 可能看起来像这样:

    #!/usr/bin/env sbcl --noinform --core /sbcl-base.core --script
    

clbuild 的优点是您可以轻松地从 shell 为 sbcl(默认情况下)或任何其他现代创建和管理 core 和 Quicklisp 安装类似 ccl64 的 CL 实现。混合使用两种技术(脚本和 clbuild)将解决您的问题。

Creating a dedicated version of core image is a good option. You may:

  1. load quicklisp and sb-ext:save-lisp-and-die in a new image. You write a shell/bat script named, say qlsbcl, like this:

    sbcl --core <my-new-image-full-path-location> "$@"
    
  2. grab clbuild2 at http://gitorious.org/clbuild2 and run clbuild lisp. You'll have to symlink clbuild to a binary directory in your path and tweak some scripts a bit if your quicklisp is not in the common place ~/quicklisp (https://gist.github.com/1485836) or if you use ASDF2 (https://gist.github.com/1621825). By doing so, clbuild create a new core with quicklisp, ASDF and anything you may add in conf.lisp. Now the shebang may look like this:

    #!/usr/bin/env sbcl --noinform --core <my-clbuild-install-directory>/sbcl-base.core --script
    

The advantage of clbuild is that you may easily create and manage core and quicklisp installation from shell for sbcl (by default) or any other modern CL like ccl64 implementation. Mixing the two techniques (script and clbuild) will solve your problem.

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