gpt4 book ai didi

lisp - 在 Common Lisp 的 Progn 中加载包

转载 作者:太空宇宙 更新时间:2023-11-03 18:42:00 24 4
gpt4 key购买 nike

我正在尝试制作一个简单的表单来自动将 Slynk 加载到图像上。

到目前为止,我有这个:

(progn 
(load "/home/user/asdf.lisp")
(format t "~% Loaded ASDF")
(push "/home/user/.emacs.d/elpa/sly-20180708.712/slynk/" asdf:*central-registry*)
(format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
(asdf:load-system :slynk)
(format t "~% Loaded ASDF system")
(slynk:create-server :port 4007 :dont-close t)
(format t "~% Created SLYNK server on port 4007")
(setf slynk:*use-dedicated-output-stream* nil)
(format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL"))

问题是每当我尝试在 REPL 中评估此表单时,我都会收到以下错误:

Error: "ASDF" is not a known package.

Restart actions (select using :continue):
0: Return NIL
1: Return to Top Level (an "abort" restart).
2: Abort entirely from this (lisp) process.
[1] CL-USER(4):

在那之前还没有打印品出现。也就是说,它似乎在第一个 push 行出错。我的理解是它还没有加载包并试图引用它的符号。

如何更改表单以使其正常工作?表格下方也有类似情况。

附言当每一行都按照给定的顺序自行执行时,一切都会完美无缺。

最佳答案

错误来自read作为它试图解析整个 progn 形式和 sees the asdf: package prefix .

您必须先加载 asdf 读者才能看到代码asdf: 包前缀 and 加载 slynk before 你使用 :slynk前缀,换句话说,将您的 progn 表单一个一个地提供给 Lisp(如您在 PS 中所说)。

另一种方法是将所有内容放在 progn 中的 中文件并加载它。您还需要制作 "20180708.712"4007 变量,例如,

(defvar *sly-version* "20180708.712")
(defvar *slynk-port* 4007)
(load "load-and-start-slynk.lisp")

load-and-start-slynk.lisp 中:

(load "/home/user/asdf.lisp")
(format t "~% Loaded ASDF")
(push (concatenate 'string "/home/user/.emacs.d/elpa/sly-"
*sly-version* "/slynk/")
asdf:*central-registry*)
(format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
(asdf:load-system :slynk)
(format t "~% Loaded ASDF system")
(slynk:create-server :port *slynk-port* :dont-close t)
(format t "~% Created SLYNK server on port ~D" *slynk-port*)
(setq slynk:*use-dedicated-output-stream* nil)
(format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL")

附言。只是为了展示如何滥用 Lisp 的力量,这里是如何做你想做的事情:

(defun load-and-start-slynk (port version)
(load "/home/user/asdf.lisp")
(format t "~% Loaded ASDF")
(push (concatenate 'string "/home/user/.emacs.d/elpa/sly-" version "/slynk/")
(symbol-value (find-symbol "*CENTRAL-REGISTRY*" '#:asdf)))
(format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
(funcall (find-symbol "LOAD-SYSTEM" '#:asdf) :slynk)
(format t "~% Loaded ASDF system")
(funcall (find-symbol "CREATE-SERVER" '#:slynk) :port port :dont-close t)
(format t "~% Created SLYNK server on port ~D" port)
(setf (symbol-value (find-symbol "*USE-DEDICATED-OUTPUT-STREAM*" '#:slynk)) nil)
(format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL"))

不要这样做。

关于lisp - 在 Common Lisp 的 Progn 中加载包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54791233/

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