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

Common Lisp使用:import-from导入符号后仍提示未定义的问题

问题解决方法

你遇到的问题核心是代码没有运行在你定义的custom-sender包中:虽然你通过:import-from把符号导入了custom-sender包,但后续调用encode-json-to-string的代码仍在默认包(比如COMMON-LISP-USER)里执行,这个默认包并没有导入该符号,所以会报错未定义。

修正后的代码写法

(ql:quickload :cl-json)

(defpackage custom-sender
  ;; 从cl-json导入指定符号到当前包
  (:import-from :cl-json :encode-json-to-string)
  ;; 导入Common Lisp的核心符号
  (:use :cl))

;; 切换到custom-sender包中执行后续代码
(in-package :custom-sender)

;; 现在可以直接调用符号,无需前缀
(encode-json-to-string .....)

额外说明

  • 如果是在REPL环境中调试,定义完包后必须手动执行(in-package :custom-sender)切换包,否则输入的代码还是在默认包中。
  • 如果你需要在多个包中使用这个符号,可以在defpackage里加上:export :encode-json-to-string,然后在其他包用:use :custom-sender或者:import-from :custom-sender :encode-json-to-string来导入。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 19:10:32