Reputation: 1941
I'm receiving a SBCL compiler warning message, which I don't understand:
; 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.
The source function generating this is as follows:
(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
All of the compiler optimization parameters are set to 1. Does anyone have an explanation or suggestions for troubleshooting this further?
Note: Edited to include entire function.
Upvotes: 1
Views: 186
Reputation: 139241
SORT may have destructive and unwanted side-effects when sorting a list.
For example here we sort a list (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)
You can see that the list pointed to by a
is not the result and its contents have been altered.
You can see the differences:
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 warns that the code does not use the result value. It's also wrong to use the side-effected list after sorting.
You should check the code and see if that is the case.
Upvotes: 4