混淆SBCL编译器消息



我正在收到一条SBCL编译器警告消息,我不明白:

; file: D:/Users Data/Dave/SW Library/AI/Planning/DAB Planner/support.lisp
; in: DEFUN UPDATE-HAPPENINGS
;     (SORT PLANNER-PKG::HAP-UPDATES #'< :KEY #'CAR)
; ==>
;   (SB-IMPL::STABLE-SORT-LIST LIST
;                              (SB-KERNEL:%COERCE-CALLABLE-TO-FUN
;                               SB-C::PREDICATE)
;                              (IF SB-C::KEY
;                                  (SB-KERNEL:%COERCE-CALLABLE-TO-FUN SB-C::KEY)
;                                  #'IDENTITY))
;
; caught STYLE-WARNING:
;   The return value of STABLE-SORT-LIST should not be discarded.
;
; caught STYLE-WARNING:
;   The return value of STABLE-SORT-LIST should not be discarded.

生成此的源函数如下:

(defun update-happenings (state act-state)
  "Updates act-state with happenings up through the action completion time
  for all happenings, and checks for constraint violation along the way."
  (declare (problem-state state act-state) (special *happenings*))
  (when (null *happenings*)
    (return-from update-happenings act-state))
  (let* ((hap-state (copy-problem-state state))  ;initialization
         (net-state (copy-problem-state act-state))  ;initialization
         (obj-hap-updates (iter (for object in *happenings*)
                                (collect (get-object-happening-update object state
                                                    (problem-state-time act-state)))))
         (next-hap-update (iter (for obj-update in obj-hap-updates)
                                (finding obj-update maximizing (second (car obj-update)))))
         (hap-updates (iter (for obj-update in obj-hap-updates)
                            (append (cdr obj-update)))))
    (setf (problem-state-happenings net-state) (car next-hap-update))
    (setf hap-updates (sort hap-updates #'< :key #'car))
    (iter (for hap-update in hap-updates)  ;compute final net-state
          (revise (problem-state-db net-state) (cdr hap-update)))
    (iter (for hap-update in hap-updates)
          (revise (problem-state-db hap-state) (cdr hap-update))
          (when (constraint-violated act-state hap-state net-state)
            (return-from update-happenings nil))  ;cancel action and exit
          (finally (return net-state)))))  ;no constraint violations encountered

所有编译器优化参数均设置为1。有人是否对此有解释或建议进行故障排除?

注意:编辑为包含整个功能。

排序时可能具有破坏性和不必要的副作用。

例如,在这里我们对列表(10 10 9 10)

进行排序
CL-USER> (funcall (lambda (&aux (a (list 10 10 9 10))) 
                     (sort a #'<)
                     a))
; in: FUNCALL (LAMBDA (&AUX (A (LIST 10 10 9 10))) (SORT A #'<) A)
;     (SORT A #'<)
; ==>
;   (SB-IMPL::STABLE-SORT-LIST LIST
;                              (SB-KERNEL:%COERCE-CALLABLE-TO-FUN
;                               SB-C::PREDICATE)
;                              (IF SB-C::KEY
;                                  (SB-KERNEL:%COERCE-CALLABLE-TO-FUN SB-C::KEY)
;                                  #'IDENTITY))
; 
; caught STYLE-WARNING:
;   The return value of STABLE-SORT-LIST should not be discarded.
; 
; caught STYLE-WARNING:
;   The return value of STABLE-SORT-LIST should not be discarded.
; 
; compilation unit finished
;   caught 2 STYLE-WARNING conditions
(10 10 10)

您可以看到a指向的列表不是结果,并且其内容已更改。

您可以看到差异:

CL-USER> (funcall (lambda (&aux (a (list 10 10 9 10))) 
            (values (sort a #'<)
                    a)))
(9 10 10 10)     ;    this is the result from SORT
(10 10 10)       ;    this is the side-effected value of A

SBCL警告该代码不使用结果值。排序后使用副作用列表也是错误的。

您应该检查代码,看看是否是这种情况。

相关内容

  • 没有找到相关文章

最新更新