Re: Mysteries of unwind-protect

"Tim Bradshaw (as tfb at tfeb dot org)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
On 15 Jan 2026, at 21:26, Michał phoe Herda <[email protected]> wrote:
> 
> I'd assume the lexical variable access cannot be optimized away in order to allow you to SETF V in the debugger like you did above. What's your DEBUG setting and does this whole issue also manifest with DEBUG 0?

It was whatever the ambient value was.  But interestingly both LW and SBCL still complain with debug 0.  And SBCL complains not where I would expect it to.  Given this:

(defun ts/nodebug (n)
  (declare (type fixnum n))
  (declare (optimize speed (debug 0) (safety 0))) ;safety tried as well
  #+LispWorks
  (declare (optimize (float 0))
           (:explain :boxing))
  (let ((v (make-array 1 :element-type 'double-float :initial-element 0.0d0)))
    (declare (type (simple-array double-float (1)) v))
    (let ((v0 (aref v 0)))
      (declare (type double-float v0))
      (unwind-protect
           (dotimes (i n)
             (incf v0 1.0d0))
        (setf (aref v 0) v0))))
  (values))

Then it will complain about the INCF, and experimentally it conses furiously.  That's not really a problem for this list though.

And with the above, LW now doesn't complain at all (and doesn't cons), so now I am really confused.

I think the answer is that unwind-protect is something you don't want to use unless you need to.  Which was what I already thought, so that's good.

--tim





_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.