all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: 29799@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#29799: 24.5; cl-loop guard clause missing
Date: Mon, 01 Jan 2018 16:46:30 -0500	[thread overview]
Message-ID: <874lo5tfpl.fsf@users.sourceforge.net> (raw)
In-Reply-To: <87d138beur.fsf@gmail.com> (Tino Calancha's message of "Thu, 21 Dec 2017 18:38:20 +0900")

Tino Calancha <tino.calancha@gmail.com> writes:

> (require 'cl-lib)
> (let* ((size 7)
>        (arr (make-vector size 0)))
>   (cl-loop for k below size
>            for x = (* 2 k) and y = (1+ (elt arr k))
>            collect (list k x y)))
>
>
> When you execute the form above it fails because
> the loop overrun `arr'.

A simpler example:

    (require 'cl-lib)
    (cl-loop for k below 3
         for x = (progn (message "k = %d" k) 1)
         and y = 1)

prints

    k = 0
    k = 1
    k = 2
    k = 3

in *Messages*.  The expansion looks like this:

    (cl-block nil
      (let* ((k 0))
        (let ((x nil)
              (y nil))
          (let* ((--cl-var-- t))
            (while (< k 3)
              (cl-psetq x
                        (if --cl-var--
                            (progn
                              (message "k = %d" k)
                              1)
                          x)
                        y (if --cl-var-- 1 y))
              (setq k (+ k 1))
              (cl-psetq x (progn
                            (message "k = %d" k)
                            1)
                        y 1)
              (setq --cl-var-- nil))
            nil))))

I don't understand why the "then" step is put at the of the loop.  The
following patch (commenting out the "ands" branch) avoids doing that,
and fixes this bug.  But presumably there is some reason for having this
code in the first place?  I guess some more complicated example would be
needed to show why this naive fix won't work.

--- i/lisp/emacs-lisp/cl-macs.el
+++ w/lisp/emacs-lisp/cl-macs.el
@@ -1288,7 +1288,7 @@ cl--parse-loop-clause
 		       (then (if (eq (car cl--loop-args) 'then)
                                  (cl--pop2 cl--loop-args) start)))
 		  (push (list var nil) loop-for-bindings)
-		  (if (or ands (eq (car cl--loop-args) 'and))
+		  (if nil ;(or ands (eq (car cl--loop-args) 'and))
 		      (progn
 			(push `(,var
 				(if ,(or cl--loop-first-flag






  reply	other threads:[~2018-01-01 21:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21  9:38 bug#29799: 24.5; cl-loop guard clause missing Tino Calancha
2018-01-01 21:46 ` Noam Postavsky [this message]
2018-01-01 22:58   ` Noam Postavsky
2018-01-03 10:34     ` Tino Calancha
2018-01-06 13:43       ` Noam Postavsky
2018-01-08 10:20         ` Tino Calancha
2019-10-28  3:59 ` dick.r.chiang
2019-11-21 23:25 ` dick.r.chiang
2019-11-22 12:55   ` Lars Ingebrigtsen
2019-11-22 13:51     ` dick.r.chiang
2019-11-22 14:53       ` Lars Ingebrigtsen

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=874lo5tfpl.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=29799@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=tino.calancha@gmail.com \
    /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.