unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice
@ 2017-03-04  8:02 Andreas Politz
  2017-03-08 21:52 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Politz @ 2017-03-04  8:02 UTC (permalink / raw)
  To: 25965


Here is an example where the behavior occurs.

#+BEGIN_SRC emacs-lisp
  ;; -*- lexical-binding: t -*-
  (iter-next
   (funcall (iter-lambda ()
              (let* ((fill-column 10) ;;any special variable will do
                     (i 0)
                     (j (setq i (1+ i))))
                (iter-yield i)))))
  ;; => 2
#+END_SRC

But the result should be 1.  Looking at the expanded code, we see i
incremented indeed twice.

#+BEGIN_SRC emacs-lisp
  ;; ....
  (setq cps-state-atom--1522
        #'(lambda nil
            (setq cps-current-value--1513
                  (let
                      ((fill-column cps-binding-fill-column--1516))
                    (unwind-protect
                        (prog1
                            (setq cps-binding-i--1517
                                  (1+ cps-binding-i--1517))
                          (setq cps-current-state--1514 cps-state-let*--1521))
                      (setq cps-binding-fill-column--1516 fill-column))
                    (prog1
                        (setq cps-binding-i--1517
                              (1+ cps-binding-i--1517))
                      (setq cps-current-state--1514 cps-state-let*--1521))))))
  ;; ...
#+END_SRC

The unwind-protect form is created in this function.

#+BEGIN_SRC emacs-lisp
  (defun cps--make-dynamic-binding-wrapper (dynamic-var static-var)
    (cl-assert lexical-binding)
    (lambda (form)
      `(let ((,dynamic-var ,static-var))
         (unwind-protect ; Update the static shadow after evaluation is done
              ,form
           (setf ,static-var ,dynamic-var))
         ,form)))
#+END_SRC

And it seems to me that the second occurrence of ,form is just an
error.

By the way, why is debugging these generators made so difficult (via the
implementation of cps--gensym) ?

-ap





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

end of thread, other threads:[~2017-10-05 19:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-04  8:02 bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice Andreas Politz
2017-03-08 21:52 ` Stefan Monnier
2017-03-08 22:08   ` Daniel Colascione
2017-09-21 21:36     ` Gemini Lasswell
2017-10-05 19:51       ` Gemini Lasswell

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).