小编Sli*_*org的帖子

为什么这个 lisp 向量没有扩展?

我正在尝试使用 SBCL 在 Common Lisp 中创建一个节点对象,该节点对象使用其文本元素进行初始化,然后链接到其他节点。我的函数链接应该采用节点“from_node”,获取其成员链接(应该是可变/可扩展向量)并推入节点“to_node”。

我编译 say.lisp,创建 2 个代表节点的全局变量,然后尝试链接这两个节点。我收到一个错误

这是say.lisp

(defclass node ()
  ((text
     :initarg :text)
   (links
     :initform (make-array 1 :adjustable t))))

(defun link (from_node to_node)
  (vector-push-extend to_node (slot-value from_node 'links)))
Run Code Online (Sandbox Code Playgroud)

然后在 REPL 中

* (load "say.lisp")  
T
* (defvar *x* (make-instance 'node :text "hello world"))

*X*
* (defvar *y* (make-instance 'node :text "bye world"))  

*Y*
* (link *x* *y*)

debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {1003016593}>:
  The value #() is not of type …
Run Code Online (Sandbox Code Playgroud)

vector sbcl common-lisp

2
推荐指数
1
解决办法
626
查看次数

标签 统计

common-lisp ×1

sbcl ×1

vector ×1