all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@hochschule-trier.de>
To: 25965@debbugs.gnu.org
Subject: bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice
Date: Sat, 04 Mar 2017 09:02:32 +0100	[thread overview]
Message-ID: <87efydcvvr.fsf@luca> (raw)


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





             reply	other threads:[~2017-03-04  8:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-04  8:02 Andreas Politz [this message]
2017-03-08 21:52 ` bug#25965: 26.0.50; iter-lambda may evaluate certain forms twice Stefan Monnier
2017-03-08 22:08   ` Daniel Colascione
2017-09-21 21:36     ` Gemini Lasswell
2017-10-05 19:51       ` Gemini Lasswell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87efydcvvr.fsf@luca \
    --to=politza@hochschule-trier.de \
    --cc=25965@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.