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

如何让SBCL程序执行指定代码后终止?原CLISP代码失效问题

解决SBCL中无法终止程序的问题

你的代码在CLISP中生效是因为bye是CLISP特有的程序终止函数,但SBCL并不支持该函数。要实现相同的终止效果,可采用以下两种方式:

1. 使用SBCL专属的终止函数

SBCL提供sb-ext:quit函数用于终止程序,同时SBCL的命令行参数变量是sb-ext:*posix-argv*(替代CLISP的*posix-argv*),修改后的调用代码如下:

(when (string= (cadr sb-ext:*posix-argv*) "--version")
    (showVersion)
    (sb-ext:quit))

2. 使用跨实现的通用终止函数

如果希望代码能在CLISP、SBCL等多个Common Lisp环境中通用,可使用uiop:quit(多数现代Common Lisp环境默认包含UIOP库),同时用跨实现的uiop:*command-line-arguments*获取命令行参数:

(when (string= (cadr uiop:*command-line-arguments*) "--version")
    (showVersion)
    (uiop:quit))

你的showVersion函数无需修改,在两个环境中均可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 07:42:04