Subject: bug#66696: 29.1; "A bug in the function debug."

From: Gerd Möllmann <[email-masked]>
Date: Mon, 23 Oct 2023 08:57:09 +0200

Lewis Creary via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> While I was trying to diagnose a bug in the function displayed just below
> with the help of the function debug, the interim values of the lisp variables shown were inconsistent with the code being debugged.  For example,
> when called with the argument 5, the first element of the remainder list should be 1 (5 divided by 2 leaves a remainder of 1).  However, the fn
> debug claims that the variable `rmdr-list' has the first element 0.  This is just wrong!  And it has nothing to do with the problem being debugged.
>
> (defun dec-to-bin (n)
>   (let ((dividend n)
>         (rmdr-list nil)
>         (stop-sw nil)
>         (numstr "") )
>     (while ((and (>= dividend 0) (not stop-sw)))
>        (setq dividend (/ dividend 2)
>              rmdr-list (append (list (% dividend 2))                                               rmdr-list) )
>        (if (= dividend 0)
>            (setq stop-sw t)) )

DId you get your parentheses right? The above ')' is the end of the while...

>        (debug) )
>     (while rmdr-list
>       (setq numstr (concat numstr (number-to-string                                          (car rmdr-list)))
>             rmdr-list (cdr rmdr-list) ) )
>     (string-to-number numstr) ))