1
我想在Common Lisp中使用用其文本元素初始化的SBCL創建一個節點對象,然後鏈接到其他節點。我的功能鏈接應該採用節點「from_node」,獲取其成員鏈接(應該是一個可變/可擴展的向量),並將節點推入「to_node」。這個lisp向量爲什麼不擴展?
我編譯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)))
然後在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 (AND VECTOR (NOT SIMPLE-ARRAY)).
Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
(VECTOR-PUSH-EXTEND #<NODE {10031D3983}> #() NIL)
0]
原本我以爲我正在一個不變的載體,但「:可調節T」應該允許這個工作。
出了什麼問題?
謝謝,函數沒有「下一個填充位置」 – SlightlyCyborg 2015-02-23 19:34:32