different results with different compiler settings
I'm trying to optimize insertion into a sorted list (LWwin 6.0.1 pro, based on [*])(defun insert-sorted (item list)
(if list
(loop :with previous-tail := nil
:for tail :on list
:for element := (first tail)
:do (if (<= item element)
(if (= item element)
(progn
(print "already present")
(return list))
(if previous-tail
(progn
(setf (cdr previous-tail) (cons item tail))
(return list))
(return (cons item list))))
(setf previous-tail tail))
:finally
(setf (cdr previous-tail) (cons item '()))
(return list))
(list item)))
(declaim (optimize (speed 3) (safety 3) (debug 3) (hcl:fixnum-safety 3)))
compile the function:
;;; Safety = 3, Speed = 3, Space = 1, Float = 1, Interruptible = 1
;;; Compilation speed = 1, Debug = 3, Fixnum safety = 3
;;; Source level debugging is on
;;; Source file recording is on
;;; Cross referencing is on
; (LISPWORKS:TOP-LEVEL-FORM 0)
; INSERT-SORTED
---- Done ----
(insert-sorted 2.5 (list 1 2 3 4 5 6 7))
==> (1 2 2.5 3 4 5 6 7)
which is the expected result.
(declaim (optimize (speed 3) (safety 0) (debug 0) (hcl:fixnum-safety 0)))
compile the function:
;;; Safety = 0, Speed = 3, Space = 1, Float = 1, Interruptible = 1
;;; Compilation speed = 1, Debug = 0, Fixnum safety = 0
;;; Source level debugging is off
;;; Source file recording is on
;;; Cross referencing is on
; (LISPWORKS:TOP-LEVEL-FORM 0)
; INSERT-SORTED
---- Done ----
(insert-sorted 2.5 (list 1 2 3 4 5 6 7))
==> (1 2 3 4 5 6 7 2.5)
which is a different result.
My understanding is that optimization settings do not change the result of a correct program.
So the program is incorrect, but I don't see it.
Would someone please be so kind to assist me in finding the solution ?
Thank you
Frank
[*] http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/914dbc19927753ed/2ab553e452542cac?lnk=gst&q=+vertebrae#2ab553e452542cac
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192 |