gpt4 book ai didi

compilation - 如何将参数传递给保存的 SBCL 核心?

转载 作者:行者123 更新时间:2023-12-03 07:44:54 26 4
gpt4 key购买 nike

我有一个 Lisp (SBCL 1.0.40.0.debian) 应用程序 (myfitnessdata),它使用以下代码来处理命令行参数:

(:use :common-lisp)
(:export #:main))

(in-package :myfitnessdata)

(require :sb-posix)

;; snip

(defun main ()
(if (= (length sb-ext:*posix-argv*) 3)
(let ((username (nth 0 sb-ext:*posix-argv*))
(password (nth 1 sb-ext:*posix-argv*))
(path (nth 2 sb-ext:*posix-argv*)))
(scrape (username password path)))
(show-usage)))

我正在使用以下 Lisp 代码编译此应用程序:

(load "myfitnessdata.lisp")
(save-lisp-and-die "myfitnessdata.bin" :executable t :toplevel 'myfitnessdata:main)

这会生成一个我可以运行的可执行文件。但是,sb-ext:*posix-argv* 列表始终为空。如果我运行以下命令:

./myfitnessdata.bin myusername mypassword /home/me/data

...那么我得到的只是(show-usage)生成的使用说明。

我想我一定又错过了一些简单的东西 - 有人可以让我知道如何(save-lisp-and-die)以便生成的可执行文件接受命令行参数吗?

最佳答案

解决方案,正如sbcl-help上的好人所建议的那样,就是使用像 buildapp 这样的工具编译应用程序。您可以指定一个入口点,该入口点被假定为具有一个参数的函数。在运行时,使用命令行参数列表调用该函数。

使用 buildapp,我的 main 功能现在是:

(defun main (args)
(if (= (length args) 4)
(let ((username (nth 1 args))
(password (nth 2 args))
(path (nth 3 args)))
(scrape username password path))
(show-usage)))

关于compilation - 如何将参数传递给保存的 SBCL 核心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com