all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#66696: 29.1; "A bug in the function debug."
       [not found] <1239664521.598080.1698039706916.ref@mail.yahoo.com>
@ 2023-10-23  5:41 ` Lewis Creary via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-10-23  6:57   ` Gerd Möllmann
  0 siblings, 1 reply; 4+ messages in thread
From: Lewis Creary via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-10-23  5:41 UTC (permalink / raw)
  To: 66696

[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]

While I was trying to diagnose a bug in the function displayed just belowwith 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)) )       (debug) )    (while rmdr-list      (setq numstr (concat numstr (number-to-string                                          (car rmdr-list)))             rmdr-list (cdr rmdr-list) ) )    (string-to-number numstr) ))-----------------------------------------------------In GNU emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-02 built on AVALONWindowing system distributor 'Microsoft Corp.', version 10.0.22621System Description: Microsoft Windows 10 Home (v10.0.2009.22621.2428)Configured using: 'configure --with-modules --without-dbus --with-native-compilation=aot --without-compress-install --with-tree-sitter CFLAGS=-O2'
Configured features:ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMPNOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFFTOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB
(NATIVE_COMP present but libgccjit not available)
Important settings:  value of $LANG: ENU  locale-coding-system: cp1252
Major mode: Lisp Interaction
Minor modes in effect:  tooltip-mode: t  global-eldoc-mode: t  eldoc-mode: t  show-paren-mode: t  electric-indent-mode: t  mouse-wheel-mode: t  tool-bar-mode: t  menu-bar-mode: t  file-name-shadow-mode: t  global-font-lock-mode: t  font-lock-mode: t  blink-cursor-mode: t  line-number-mode: t  indent-tabs-mode: t  transient-mark-mode: t  auto-composition-mode: t  auto-encryption-mode: t  auto-compression-mode: t
 

[-- Attachment #2: Type: text/html, Size: 5693 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#66696: 29.1; "A bug in the function debug."
  2023-10-23  5:41 ` Lewis Creary via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-10-23  6:57   ` Gerd Möllmann
  0 siblings, 0 replies; 4+ messages in thread
From: Gerd Möllmann @ 2023-10-23  6:57 UTC (permalink / raw)
  To: 66696; +Cc: lewcreary

Lewis Creary via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> 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) ))





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#66696: 29.1; "A bug in the function debug."
       [not found] ` <556885424.775162.1698086427787@mail.yahoo.com>
@ 2023-10-23 19:11   ` Gerd Möllmann
  2023-11-05  6:00     ` Gerd Möllmann
  0 siblings, 1 reply; 4+ messages in thread
From: Gerd Möllmann @ 2023-10-23 19:11 UTC (permalink / raw)
  To: Lewis Creary; +Cc: 66696

Lewis Creary <lewcreary@cs.com> writes:

(Please reply to all, so that your mails get to the bug tracker.)

>>> Did you get your parentheses right? The above ')' is the end of the while.
>
> I checked, and the extra parenthesis is in my bug report, but not in the code I tried to run.  I'd be interested to know if you can reproduce my
> problem in emacs lisp, with correct parentheses.
>
>    --  Lew Creary

1:    (while ((and (>= dividend 0) (not stop-sw)))
2:       (setq dividend (/ dividend 2)
3:             rmdr-list (append (list (% dividend 2)) rmdr-list) )

You write in the bug report that you start with dividend being 5, and
you expect the first element of the list to be 1, but it is 0.

When you look at line 2, dividend is divided by 2, which results in 5 /
2 = 2, because this is integer division.  In line 3, you compute the rest
of dividend (which is now 2) when divided by 2, which results in 0.

So, this looks correct.







^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#66696: 29.1; "A bug in the function debug."
  2023-10-23 19:11   ` bug#66696: 29.1; "A bug in the function debug." Gerd Möllmann
@ 2023-11-05  6:00     ` Gerd Möllmann
  0 siblings, 0 replies; 4+ messages in thread
From: Gerd Möllmann @ 2023-11-05  6:00 UTC (permalink / raw)
  To: Lewis Creary; +Cc: 66696

Gerd Möllmann <gerd.moellmann@gmail.com> writes:

> Lewis Creary <lewcreary@cs.com> writes:
>
> (Please reply to all, so that your mails get to the bug tracker.)
>
>>>> Did you get your parentheses right? The above ')' is the end of the while.
>>
>> I checked, and the extra parenthesis is in my bug report, but not in the code I tried to run.  I'd be interested to know if you can reproduce my
>> problem in emacs lisp, with correct parentheses.
>>
>>    --  Lew Creary
>
> 1:    (while ((and (>= dividend 0) (not stop-sw)))
> 2:       (setq dividend (/ dividend 2)
> 3:             rmdr-list (append (list (% dividend 2)) rmdr-list) )
>
> You write in the bug report that you start with dividend being 5, and
> you expect the first element of the list to be 1, but it is 0.
>
> When you look at line 2, dividend is divided by 2, which results in 5 /
> 2 = 2, because this is integer division.  In line 3, you compute the rest
> of dividend (which is now 2) when divided by 2, which results in 0.
>
> So, this looks correct.

No further reaction expected at this point, so I'm closing this. 





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-05  6:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <556885424.775162.1698086427787.ref@mail.yahoo.com>
     [not found] ` <556885424.775162.1698086427787@mail.yahoo.com>
2023-10-23 19:11   ` bug#66696: 29.1; "A bug in the function debug." Gerd Möllmann
2023-11-05  6:00     ` Gerd Möllmann
     [not found] <1239664521.598080.1698039706916.ref@mail.yahoo.com>
2023-10-23  5:41 ` Lewis Creary via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-23  6:57   ` Gerd Möllmann

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.